diff --git a/DataProcessingTools/objects.py b/DataProcessingTools/objects.py index fd6a567..e0c63b7 100644 --- a/DataProcessingTools/objects.py +++ b/DataProcessingTools/objects.py @@ -65,11 +65,11 @@ def __init__(self, *args, **kwargs): def create(self, *args, **kwargs): self.dirs = kwargs.get("dirs", [os.getcwd()]) + self.setidx = [] if self.dirs: normpath = kwargs.get("normpath", True) if normpath: self.dirs = [levels.normpath(d) for d in self.dirs] - self.setidx = [] self.plotopts = {"indexer": self.level} self.indexer = self.getindex(self.level) self.current_idx = None @@ -239,6 +239,8 @@ def processDirs(dirs, objtype, *args, **kwargs): """ if dirs is None: dirs = levels.get_level_dirs(objtype.level) + if not dirs: + return objtype(dirs=[]) ii = 0 while ii < len(dirs): diff --git a/tests/test_objects.py b/tests/test_objects.py index 4dec788..e2927c6 100644 --- a/tests/test_objects.py +++ b/tests/test_objects.py @@ -77,13 +77,17 @@ def test_append(): # do the same thing with processDirs obj3 = DPT.objects.processDirs(dirs, MyObj, [0.1, 0.2, 0.3]) obj4 = DPT.objects.processDirs(None, MyObj, [0.1, 0.2, 0.3]) + obj5 = DPT.objects.processDirs([], MyObj, [0.1, 0.2, 0.3]) + assert obj1.setidx == [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3] assert obj3.setidx == obj1.setidx assert obj4.setidx == obj3.setidx + assert obj5.setidx == [] assert obj1.dirs == dirs assert obj1.dirs == obj3.dirs assert obj1.dirs == obj4.dirs + assert obj5.dirs == [] mylevels = obj1.getlevels() assert mylevels == ["subject", "day", "session","array","channel","cell"]