# Buggy code
def _is_valid(self, *args, **kwargs):
    need_groups = ["Constants", "Header", "Parameters", "Units"]
    veto_groups = [
        "SUBFIND",
        "FOF",
        "PartType0/ChemistryAbundances",
        "PartType0/ChemicalAbundances",
        "RuntimePars",
        "HashTable",
    ]
    valid = True
    valid_fname = args[0]
    # If passed arg is a directory, look for the .0 file in that dir
    if os.path.isdir(args[0]):
        valid_files = []
        for f in os.listdir(args[0]):
            fname = os.path.join(args[0], f)
            if (".0" in f) and (".ewah" not in f) and os.path.isfile(fname):
                valid_files.append(fname)
        if len(valid_files) == 0:
            valid = False
        elif len(valid_files) > 1:
            valid = False
        else:
            valid_fname = valid_files[0]
    try:
        fileh = h5py.File(valid_fname, mode="r")
        for ng in need_groups:
            if ng not in fileh["/"]:
                valid = False
        for vg in veto_groups:
            if vg in fileh["/"]:
                valid = False
        fileh.close()
    except Exception:
        valid = False
        pass
    return valid


# Traceback (OSError)
Traceback (most recent call last):
File "ala.py", line 2, in <module>
ds = OWLSDataset("/home/xarth/codes/yt_data/snapshot_033/")
File "/home/xarth/codes/xarthisius/yt/yt/frontends/gadget/data_structures.py", line 571, in __init__
super(GadgetHDF5Dataset, self).__init__(
File "/home/xarth/codes/xarthisius/yt/yt/frontends/gadget/data_structures.py", line 303, in __init__
super(GadgetDataset, self).__init__(
File "/home/xarth/codes/xarthisius/yt/yt/frontends/sph/data_structures.py", line 34, in __init__
super(SPHDataset, self).__init__(
File "/home/xarth/codes/xarthisius/yt/yt/data_objects/static_output.py", line 1743, in __init__
super(ParticleDataset, self).__init__(
File "/home/xarth/codes/xarthisius/yt/yt/data_objects/static_output.py", line 256, in __init__
self._parse_parameter_file()
File "/home/xarth/codes/xarthisius/yt/yt/frontends/owls/data_structures.py", line 19, in _parse_parameter_file
hvals = self._get_hvals()
File "/home/xarth/codes/xarthisius/yt/yt/frontends/gadget/data_structures.py", line 583, in _get_hvals
handle = h5py.File(self.parameter_filename, mode="r")
File "/home/xarth/.local/lib/python3.8/site-packages/h5py/_hl/files.py", line 406, in __init__
fid = make_fid(name, mode, userblock_size,
File "/home/xarth/.local/lib/python3.8/site-packages/h5py/_hl/files.py", line 173, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5f.pyx", line 88, in h5py.h5f.open
OSError: Unable to open file (file signature not found)

# Fixed code
def _is_valid(self, *args, **kwargs):
    need_groups = ["Constants", "Header", "Parameters", "Units"]
    veto_groups = [
        "SUBFIND",
        "FOF",
        "PartType0/ChemistryAbundances",
        "PartType0/ChemicalAbundances",
        "RuntimePars",
        "HashTable",
    ]
    valid = True
    valid_fname = args[0]
    # If passed arg is a directory, look for the .0 file in that dir
    if os.path.isdir(args[0]):
        valid_files = []
        for f in os.listdir(args[0]):
            fname = os.path.join(args[0], f)
            fext = os.path.splitext(fname)[-1]
            if (
                (".0" in f)
                and (fext not in {".ewah", ".kdtree"})
                and os.path.isfile(fname)
            ):
                valid_files.append(fname)
        if len(valid_files) == 0:
            valid = False
        elif len(valid_files) > 1:
            valid = False
        else:
            valid_fname = valid_files[0]
    try:
        fileh = h5py.File(valid_fname, mode="r")
        for ng in need_groups:
            if ng not in fileh["/"]:
                valid = False
        for vg in veto_groups:
            if vg in fileh["/"]:
                valid = False
        fileh.close()
    except Exception:
        valid = False
        pass
    return valid