def get(self): """Get the dataloader """ from kipoi.data import BaseDataLoader from copy import deepcopy obj = load_obj(self.defined_as) # check that it inherits from BaseDataLoader if not inherits_from(obj, BaseDataLoader): raise ValueError( "Dataloader: {} doen't inherit from kipoi.data.BaseDataLoader". format(self.defined_as)) # override the default arguments if self.default_args: obj = override_default_kwargs(obj, self.default_args) # override also the values in the example in case # they were previously specified for k, v in self.default_args.items(): if not isinstance(obj.args[k].example, UNSPECIFIED): obj.args[k].example = v return obj
def get(self): """Get the dataloader """ from kipoi.data import BaseDataLoader from copy import deepcopy from kipoi_utils.external.related.fields import UNSPECIFIED obj = load_obj(self.defined_as) # check that it inherits from BaseDataLoader if not inherits_from(obj, BaseDataLoader): raise ValueError(f"Dataloader: {self.defined_as} doen't inherit from kipoi.data.BaseDataLoader") # override the default arguments if self.default_args: obj = override_default_kwargs(obj, self.default_args) # override also the values in the example in case # they were previously specified # TODO: How to modify this code with KipoiDataLoaderImport in mind? for k, v in self.default_args.items(): if not isinstance(obj.args[k].example, UNSPECIFIED): obj.args[k].example = v return obj
def test_import_module_cls(): cls = load_obj("kipoi_utils.utils.Slice_conv") assert cls == kipoi_utils.utils.Slice_conv
def test_load_obj(): with pytest.raises(ImportError): load_obj("asd.dsa") with pytest.raises(ImportError): load_obj("keras.dsa")
def test_import_module_fn(): fn = load_obj("kipoi_utils.utils.read_pickle") assert fn == kipoi_utils.utils.read_pickle