-
-
Notifications
You must be signed in to change notification settings - Fork 26k
MAINT make explicit casting when using iloc #23649
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
Conversation
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.
When I run the snippet in the pandas whats new on pandas 1.4.2:
import numpy as np
import pandas as pd
values = np.arange(4).reshape(2, 2)
df = pd.DataFrame(values)
ser = df[0]
df.iloc[:, 0] = np.array([10, 11])
print(ser)
print("version", pd.__version__)
I see that iloc
operates in place:
0 10
1 11
Name: 0, dtype: int64
version 1.4.2
Given that, since this PR removes the FutureWarning
, this LGTM.
@@ -58,7 +58,7 @@ def _calculate_permutation_scores( | |||
if hasattr(X_permuted, "iloc"): | |||
col = X_permuted.iloc[shuffling_idx, col_idx] | |||
col.index = X_permuted.index | |||
X_permuted.iloc[:, col_idx] = col |
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 is a bit weird to use a slightly more complicated syntax just to avoid a warning but oh well I don't think there is anything better to do ...
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 am still thinking about how to permute the values of a dataframe column ignoring the indices.
Thanks a lot merging! |
@thomasjpfan the pandas whats new entry is very misleading, I opened pandas-dev/pandas#47433 to improve it but it has not been merged yet. IMO when doing |
Addresses the
FutureWarning
raised by pandas in the following condition:https://pandas.pydata.org/docs/dev/whatsnew/v1.5.0.html#try-operating-inplace-when-setting-values-with-loc-and-iloc