Skip to content

Commit

Permalink
add optional eid field to join to record
Browse files Browse the repository at this point in the history
  • Loading branch information
oliche committed Oct 25, 2024
1 parent dfb4846 commit a418fd6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions one/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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'])
Expand Down

0 comments on commit a418fd6

Please sign in to comment.