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 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 test_inherits_from(): class MyBaseDataLoader(object): pass class MyDataset(MyBaseDataLoader): pass class A(MyDataset): pass class B(object): pass assert inherits_from(A, MyBaseDataLoader) assert inherits_from(A, MyDataset) assert inherits_from(MyDataset, MyBaseDataLoader) assert not inherits_from(B, MyBaseDataLoader) assert not inherits_from(B, MyDataset)
def dont_test_DataLoaderImport(): imp = DataLoaderImport(defined_as='kipoi.data.Dataset') a = imp.get() assert a == kipoi.data.Dataset assert inherits_from(a, kipoi.data.BaseDataLoader)