Skip to content

Commit

Permalink
record2path supports UUID in filename
Browse files Browse the repository at this point in the history
  • Loading branch information
k1o0 committed Oct 31, 2023
1 parent e21b75f commit d922469
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions one/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ def record2path(self, dataset) -> Optional[Path]:
assert isinstance(dataset, pd.Series) or len(dataset) == 1
session_path, rel_path = dataset[['session_path', 'rel_path']].to_numpy().flatten()
file = Path(self.cache_dir, session_path, rel_path)
if self.uuid_filenames:
i = dataset.name if isinstance(dataset, pd.Series) else dataset.index[0]
file = add_uuid_string(file, i[1] if isinstance(i, tuple) else i)
return file # files[0] if len(datasets) == 1 else files

@recurse
Expand Down
12 changes: 11 additions & 1 deletion one/tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,23 @@ def test_record2path(self):
alf_path = ('hoferlab/Subjects/SWC_043/2020-09-21/001/'
'alf/probe00/_phy_spikes_subset.channels.npy')
expected = Path(self.one.alyx.cache_dir).joinpath(*alf_path.split('/'))
path = self.one.record2path(rec.loc[(self.eid, '00c234a3-a4ff-4f97-a522-939d15528a45')])
data_id = '00c234a3-a4ff-4f97-a522-939d15528a45'
path = self.one.record2path(rec.loc[(self.eid, data_id)])
self.assertIsInstance(path, Path)
self.assertEqual(expected, path)
# As pd.DataFrame
idx = rec.rel_path == 'alf/probe00/_phy_spikes_subset.channels.npy'
path = self.one.record2path(rec[idx])
self.assertEqual(expected, path)
# With UUID in file name
try:
self.one.uuid_filenames = True
expected = expected.with_suffix(f'.{data_id}.npy')
self.assertEqual(expected, self.one.record2path(rec[idx])) # as pd.DataFrame
self.assertEqual(expected, self.one.record2path(rec[idx].squeeze())) # as pd.Series
self.assertEqual(expected, self.one.record2path(rec[idx].droplevel(0))) # no eid
finally:
self.one.uuid_filenames = False

def test_eid2path(self):
"""Test for OneAlyx.eid2path"""
Expand Down

0 comments on commit d922469

Please sign in to comment.