Skip to content

PositionGroup.fetch_position_info() breaks if merge ids order does not match chronological order of the positions #1471

@gshvarts

Description

@gshvarts

I'm running into an issue where PositionGroup.fetch_position_info() returns an empty dataframe and have narrowed it down to what I think is a bug at the end of the fetch_position() function.

The two pos_merge_ids that I'm trying to combine into a position group are as follows:
run session 04_r2 (happens first): UUID('a7585350-6b4b-8f46-b4c9-e350ecffc1b6')
sleep session 05_s3 (happens second): UUID('141c4c08-ec23-114f-ebbf-0168fc3b2b42')

Although I pass these keys into PositionGroup().create_group() via a list of dicts in the above order, they end up getting iterated through in alphabetically-sorted order in PositionGroup.fetch_position() which results in the position_info dataframe containing the sleep position info (chronologically later) first and the run position info (chronologically earlier) second. Because of this, once the dataframes are concatenated and indexed from [min_time: max_time] (see line 231 in spyglass.decoding.v1.core.py), this returns an empty dataframe.

Instead, I think the concatenated dataframe should be sorted by the time index prior to doing the min_time, max_time indexing.

I've replaced the original line 231 with
position_info = pd.concat(position_info, axis=0).sort_index().loc[min_time:max_time] in my own code and that solved the issue for me!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions