From b8c25ac0b716101d387e9a938e7e0544982bfae2 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 10 Oct 2018 11:30:18 -0400 Subject: [PATCH 1/3] BF: make namedtuple representation consistent with File attributes Original reason - to make https://github.com/bids-standard/pybids/blob/master/examples/pybids%20tutorial.ipynb great again. ATM was crashing since returned by search File named tuples (BTW confusing/overlapping with File class in the actual File class) had no .path which File has --- grabbit/core.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/grabbit/core.py b/grabbit/core.py index 04e2a0c..a26823d 100644 --- a/grabbit/core.py +++ b/grabbit/core.py @@ -104,8 +104,10 @@ def as_named_tuple(self): "representing a File as a namedtuple. Replacing " "entities %s with safe versions %s." % (keys, safe)) entities = dict(zip(keys, self.entities.values())) - _File = namedtuple('File', 'filename ' + ' '.join(entities.keys())) - return _File(filename=self.path, **entities) + _File = namedtuple('File', 'path filename dirname ' + ' '.join(entities.keys())) + return _File(path=self.path, + filename=self.filename, dirname=self.dirname, + **entities) def copy(self, path_patterns, symbolic_link=False, root=None, conflicts='fail'): From dbb642beb7abda29ed9621642c5dc1b3528542a9 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 10 Oct 2018 11:33:53 -0400 Subject: [PATCH 2/3] BF(TST): adjusted test for the change in tuple to reflect File fields --- grabbit/tests/test_core.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/grabbit/tests/test_core.py b/grabbit/tests/test_core.py index 29eb02a..36283f3 100644 --- a/grabbit/tests/test_core.py +++ b/grabbit/tests/test_core.py @@ -84,7 +84,7 @@ def test_named_tuple(self, file): file = copy(file) file.tags = {'attrA': Tag(None, 'apple'), 'attrB': Tag(None, 'banana')} tup = file.as_named_tuple() - assert(tup.filename == file.path) + assert(tup.path == file.path) assert isinstance(tup, tuple) assert not hasattr(tup, 'task') assert tup.attrA == 'apple' @@ -203,12 +203,13 @@ def test_absolute_paths(self, bids_layout): layout = Layout([(root, config)], absolute_paths=True) result = layout.get(subject=1, run=1, session=1) assert result - assert all([os.path.isabs(f.filename) for f in result]) + assert all([os.path.isabs(f.path) for f in result]) + assert not any([os.path.isabs(f.filename) for f in result]) layout = Layout([(root, config)], absolute_paths=False) result = layout.get(subject=1, run=1, session=1) assert result - assert not any([os.path.isabs(f.filename) for f in result]) + assert not any([os.path.isabs(f.path) for f in result]) # Should always be absolute paths on HDFS else: From efcc6bd0e5af487f9aebb4318014abb1a2f11775 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 10 Oct 2018 11:30:52 -0400 Subject: [PATCH 3/3] RF: File tuple to FileTuple to disambiguate with File class --- grabbit/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grabbit/core.py b/grabbit/core.py index a26823d..ffc5b72 100644 --- a/grabbit/core.py +++ b/grabbit/core.py @@ -104,8 +104,8 @@ def as_named_tuple(self): "representing a File as a namedtuple. Replacing " "entities %s with safe versions %s." % (keys, safe)) entities = dict(zip(keys, self.entities.values())) - _File = namedtuple('File', 'path filename dirname ' + ' '.join(entities.keys())) - return _File(path=self.path, + _FileTuple = namedtuple('FileTuple', 'path filename dirname ' + ' '.join(entities.keys())) + return _FileTuple(path=self.path, filename=self.filename, dirname=self.dirname, **entities)