""""""# Created by Wenjie Du <wenjay.du@gmail.com># License: BSD-3-ClausefromtypingimportUnionimporth5py
[docs]defkey_in_data_set(key:str,dataset:Union[str,dict])->bool:"""Check if the key is in the given dataset. The dataset could be a path to an HDF5 file or a Python dictionary. Parameters ---------- key : The key to check. dataset : The dataset to be checked. Returns ------- bool Whether the key is in the dataset. """ifisinstance(dataset,str):withh5py.File(dataset,"r")asf:returnkeyinf.keys()elifisinstance(dataset,dict):returnkeyindataset.keys()else:raiseTypeError(f"dataset must be a str or a Python dictionary, but got {type(dataset)}")