# Buggy code
def _is_valid(self, *args, **kwargs):
    """Checks whether the supplied file can be read by this frontend."""
    warn_h5py(args[0])
    try:
        f = h5.File(args[0], "r")
    except (IOError, OSError, ImportError):
        return False

    requirements = ["openPMD", "basePath", "meshesPath", "particlesPath"]
    attrs = list(f["/"].attrs.keys())
    for i in requirements:
        if i not in attrs:
            f.close()
            return False

    known_versions = [StrictVersion("1.0.0"), StrictVersion("1.0.1")]
    if StrictVersion(f.attrs["openPMD"].decode()) in known_versions:
        f.close()
        return True
    else:
        f.close()
        return False


# Traceback (KeyError)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-6-606762cc9ee1> in <module>()
----> 1 yt.load('./example-ptcl/hdf5/data00000400.h5')

~/miniconda3/lib/python3.6/site-packages/yt/convenience.py in load(*args, **kwargs)
84     candidates = find_lowest_subclasses(candidates)
85     if len(candidates) == 1:
---> 86         return candidates[0](*args, **kwargs)
87     if len(candidates) == 0:
88         if ytcfg.get("yt", "enzo_db") != '' \

~/miniconda3/lib/python3.6/site-packages/yt/frontends/open_pmd/data_structures.py in __init__(self, filename, dataset_type, storage_filename, units_override, unit_system, **kwargs)
385         self.storage_filename = storage_filename
386         self.fluid_types += ("openPMD",)
--> 387         particles = tuple(str(c) for c in self._handle[self.base_path + self.particles_path].keys())
388         if len(particles) > 1:
389             # Only use on-disk particle names if there is more than one species

~/miniconda3/lib/python3.6/site-packages/yt/utilities/file_handler.py in __getitem__(self, key)
43
44     def __getitem__(self, key):
---> 45         return self.handle[key]
46
47     def __contains__(self, item):

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/h5py_1496887972496/work/h5py/_objects.c:2846)()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/h5py_1496887972496/work/h5py/_objects.c:2804)()

~/miniconda3/lib/python3.6/site-packages/h5py/_hl/group.py in __getitem__(self, name)
167                 raise ValueError("Invalid HDF5 object reference")
168         else:
--> 169             oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
170
171         otype = h5i.get_type(oid)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/h5py_1496887972496/work/h5py/_objects.c:2846)()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/h5py_1496887972496/work/h5py/_objects.c:2804)()

h5py/h5o.pyx in h5py.h5o.open (/Users/ilan/minonda/conda-bld/h5py_1496887972496/work/h5py/h5o.c:3740)()

KeyError: "Unable to open object (Object 'particles' doesn't exist)"

# Fixed code
def _is_valid(self, *args, **kwargs):
    """Checks whether the supplied file can be read by this frontend."""
    warn_h5py(args[0])
    try:
        with h5.File(args[0], "r") as f:
            attrs = list(f["/"].attrs.keys())
            for i in opmd_required_attributes:
                if i not in attrs:
                    return False

            if StrictVersion(f.attrs["openPMD"].decode()) not in ompd_known_versions:
                return False

            if f.attrs["iterationEncoding"].decode() == "fileBased":
                return True

            return False
    except (IOError, OSError, ImportError):
        return False