Skip to content

Commit

Permalink
Merge pull request #107 from int-brain-lab/hotfix/2.5.3
Browse files Browse the repository at this point in the history
support non-zero-padded sequence paths in ConvertersMixin.path2ref
  • Loading branch information
k1o0 authored Jan 16, 2024
2 parents c5db149 + eeb5659 commit 656e6d3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog
## [Latest](https://github.com/int-brain-lab/ONE/commits/main) [2.5.2]
## [Latest](https://github.com/int-brain-lab/ONE/commits/main) [2.5.3]

### Modified

- support non-zero-padded sequence paths in ConvertersMixin.path2ref, e.g. subject/2020-01-01/1

## [2.5.2]

### Modified

Expand Down
2 changes: 1 addition & 1 deletion one/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""The Open Neurophysiology Environment (ONE) API."""
__version__ = '2.5.2'
__version__ = '2.5.3'
17 changes: 9 additions & 8 deletions one/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def wrapper_decorator(*args, **kwargs):


class ConversionMixin:
"""A mixin providing methods to interconvert experiment identifiers"""
"""A mixin providing methods to interconvert experiment identifiers."""

def __init__(self):
self._cache = None
Expand Down Expand Up @@ -153,7 +153,7 @@ def to_eid(self,
@recurse
def eid2path(self, eid: str) -> Optional[Listable(Path)]:
"""
From an experiment id or a list of experiment ids, gets the local cache path
From an experiment id or a list of experiment ids, gets the local cache path.
Parameters
----------
Expand Down Expand Up @@ -182,7 +182,7 @@ def eid2path(self, eid: str) -> Optional[Listable(Path)]:
@recurse
def path2eid(self, path_obj):
"""
From a local path, gets the experiment id
From a local path, gets the experiment id.
Parameters
----------
Expand Down Expand Up @@ -287,7 +287,7 @@ def path2url(self, filepath):
return unwrap(self.record2url)(record)

def record2url(self, record):
"""Convert a session or dataset record to a remote URL
"""Convert a session or dataset record to a remote URL.
NB: Requires online instance
Expand Down Expand Up @@ -325,7 +325,7 @@ def record2url(self, record):
def record2path(self, dataset) -> Optional[Path]:
"""
Given a set of dataset records, checks the corresponding exists flag in the cache
correctly reflects the files system
correctly reflects the files system.
Parameters
----------
Expand Down Expand Up @@ -465,7 +465,8 @@ def ref2path(self, ref):
@parse_values
def path2ref(path_str: Union[str, Path, Iter], as_dict=True) -> Union[Bunch, List]:
"""
Returns a human readable experiment reference, given a session path.
Returns a human-readable experiment reference, given a session path.
The path need not exist.
Parameters
Expand Down Expand Up @@ -494,9 +495,9 @@ def path2ref(path_str: Union[str, Path, Iter], as_dict=True) -> Union[Bunch, Lis
"""
if isinstance(path_str, (list, tuple)):
return [unwrap(ConversionMixin.path2ref)(x) for x in path_str]
pattern = r'(?P<subject>[\w-]+)([\\/])(?P<date>\d{4}-\d{2}-\d{2})(\2)(?P<sequence>\d{3})'
pattern = r'(?P<subject>[\w-]+)([\\/])(?P<date>\d{4}-\d{2}-\d{2})(\2)(?P<sequence>\d{1,3})'
match = re.search(pattern, str(path_str))
if match:
if match and not re.match(r'^0\d$', match.groups()[-1]): # e.g. '02' not valid
ref = match.groupdict()
return Bunch(ref) if as_dict else '{date:s}_{sequence:s}_{subject:s}'.format(**ref)

Expand Down
6 changes: 6 additions & 0 deletions one/tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ def test_path2ref(self):
{'subject': 'CSHL046', 'date': datetime.date(2020, 6, 20), 'sequence': 2}
]
self.assertCountEqual(expected, refs)
# Check support of non-zero-padded sequences
ref = self.one.path2ref(path_str.with_name('1'), as_dict=False)
self.assertEqual('2018-07-13_1_flowers', ref)
# The regex matches sequence length between 1 and 3. If zero-padded, must be 3 digits.
path_str4 = path_str.with_name('01')
self.assertIsNone(self.one.path2ref(path_str4, as_dict=False))

def test_ref2path(self):
ref = {'subject': 'flowers', 'date': datetime.datetime(2018, 7, 13).date(), 'sequence': 1}
Expand Down

0 comments on commit 656e6d3

Please sign in to comment.