Skip to content

Conversation

@larsoner
Copy link
Member

Closes #12346

Not a pandas expert but mne/tests/test_epochs.py passes on my machine now and metadata.dtypes and contents look reasonable at first look

Copy link
Member Author

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-merging to keep things clean but @drammock @hoechenberger if you see a cleaner fix feel free to comment!

]

data = np.empty((len(events_df), len(columns)))
data = np.empty((len(events_df), len(columns)), float)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be explicit that we initialize with float dtype for our dataframe


# Event names
metadata.iloc[:, 0] = ""
metadata["event_name"] = ""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and Pandas does not seem to complain when you set an entire col (or list of cols) rather than using .iloc, so I go that route here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is okay

@larsoner larsoner merged commit d2c806c into mne-tools:main Jan 10, 2024
@larsoner larsoner deleted the pandas branch January 10, 2024 16:22
snwnde pushed a commit to snwnde/mne-python that referenced this pull request Mar 20, 2024
@cbrnr
Copy link
Contributor

cbrnr commented Mar 21, 2024

This would be an important backport candidate, because the issue affects pandas >= 2.1.0 (so not just pre-releases). But I guess the 1.7 release is around the corner and it's not worth it? If it's more than three weeks out, a bugfix release would probably be a good idea. WDYT?

# keep_first and keep_last names
start_idx = stop_idx
metadata.iloc[:, start_idx:] = None
metadata[columns[start_idx:]] = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is guaranteed to work in-place (now and in the future). The cleaner approach for this specific case here is definitely through using .loc or iloc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this is a problem here; usually, the infamous SettingWithCopyWarning appears only after chaining two or more indexing operations (https://pandas.pydata.org/docs/user_guide/indexing.html#indexing-view-versus-copy).

Also, the previous line triggered the FutureWarning – do you have an alternative suggestion how to typecast the column (to object) and then set its entries to None?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case I'm wrong, do you have a link for a list of channel labels not being safe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok let's keep it, then :)

@larsoner
Copy link
Member Author

because the issue affects pandas >= 2.1.0 (so not just pre-releases).

When you say it affects those versions of Pandas, do you mean it emits a FutureWarning (which wouldn't be worth a backport release) or because it actually breaks / emits an error / does something incorrect (which would be)? I'm guessing it's the former unless pandas deprecation cycle is even shorter than ours

@cbrnr
Copy link
Contributor

cbrnr commented Mar 21, 2024

Yes, it just emits a FutureWarning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Epochs metadata FutureWarning

3 participants