Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 2 commits into from
Jun 22, 2022

Conversation

glemaitre
Copy link
Member

@glemaitre glemaitre marked this pull request as draft June 16, 2022 13:03
@glemaitre glemaitre marked this pull request as ready for review June 16, 2022 13:41
Copy link
Member

@thomasjpfan thomasjpfan left a 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
Copy link
Member

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 ...

Copy link
Member Author

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.

@lesteve
Copy link
Member

lesteve commented Jun 22, 2022

Thanks a lot merging!

@lesteve lesteve merged commit ac8dd1d into scikit-learn:main Jun 22, 2022
@lesteve
Copy link
Member

lesteve commented Jun 22, 2022

@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 df.iloc[:, 0] = ..., I think that 99% of the people care that the 0th column is updated and not really whether the underlying array is updated in place or a new array is created. Having said that, there is likely no simple way to warn the remaining 1% about the subtle behaviour change ...

ogrisel pushed a commit to ogrisel/scikit-learn that referenced this pull request Jul 11, 2022
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.

3 participants