From d92246906a9b98a030ac77edd373dc1a60520fa5 Mon Sep 17 00:00:00 2001 From: Miles Wells Date: Tue, 31 Oct 2023 17:35:14 +0200 Subject: [PATCH] record2path supports UUID in filename --- one/converters.py | 3 +++ one/tests/test_converters.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/one/converters.py b/one/converters.py index 5fb779d3..312409ef 100644 --- a/one/converters.py +++ b/one/converters.py @@ -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 diff --git a/one/tests/test_converters.py b/one/tests/test_converters.py index 856465c2..0a979c5f 100644 --- a/one/tests/test_converters.py +++ b/one/tests/test_converters.py @@ -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"""