-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
MAINT: Fix for pandas pre #12347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MAINT: Fix for pandas pre #12347
Conversation
larsoner
left a comment
There was a problem hiding this 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) |
There was a problem hiding this comment.
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"] = "" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is okay
|
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:]] = "" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
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 |
|
Yes, it just emits a |
Closes #12346
Not a pandas expert but
mne/tests/test_epochs.pypasses on my machine now andmetadata.dtypesand contents look reasonable at first look