diff --git a/one/converters.py b/one/converters.py index 20b80ea7..4c0f292e 100644 --- a/one/converters.py +++ b/one/converters.py @@ -289,7 +289,7 @@ def path2url(self, filepath): return return unwrap(self.record2url)(record) - def record2url(self, record): + def record2url(self, record, eid=None): """Convert a session or dataset record to a remote URL. NB: Requires online instance @@ -299,6 +299,9 @@ def record2url(self, record): record : pd.Series, pd.DataFrame A datasets or sessions cache record. If DataFrame, iterate over and returns list. + eid: str + Optional: Session UUID. If the record comes from a cache table, the session field + needs joining and omitting this argument will result in an error Returns ------- str, list @@ -308,7 +311,7 @@ def record2url(self, record): assert webclient, 'No Web client found for instance' # FIXME Should be OneAlyx converter only if isinstance(record, pd.DataFrame): - return [self.record2url(r) for _, r in record.iterrows()] + return [self.record2url(r, eid=eid) for _, r in record.iterrows()] elif isinstance(record, pd.Series): is_session_record = 'rel_path' not in record if is_session_record: @@ -319,7 +322,11 @@ def record2url(self, record): else: raise TypeError( f'record must be pandas.DataFrame or pandas.Series, got {type(record)} instead') - assert isinstance(record.name, tuple) and len(record.name) == 2 + if not (isinstance(record.name, tuple) and len(record.name) == 2): + if eid is None: + raise ValueError( + f"Record \n {record} \n Can't be converted to URL without the eid argument") + record.name = (eid, record.name) eid, uuid = record.name # must be (eid, did) session_path = self.eid2path(eid) url = PurePosixPath(get_alf_path(session_path), record['rel_path'])