-
-
Couldn't load subscription status.
- Fork 151
Fix nightly with pd.DataFrame.rename calling for MultiIndex.fillna #1449
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
|
/pandas_nightly |
|
https://github.com/pandas-dev/pandas-stubs/actions/runs/18793416801/job/53628688389 Nightly pandas is passing |
| # Apparently all of these calls are accepted by pandas | ||
| check(assert_type(df.rename(columns={None: "b"}), pd.DataFrame), pd.DataFrame) | ||
| check(assert_type(df.rename(columns={"": "b"}), pd.DataFrame), pd.DataFrame) | ||
| check(assert_type(df.rename(columns={(2, 1): "b"}), pd.DataFrame), pd.DataFrame) |
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.
Could you change the stub files and invalidate this usage?
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.
That would actually break, the issue is at run time when you try to rename a dataframe with an Index when the mapper is designed for a multiindex. Since we do not have the capacity to differenciate 'dataframe with index' and 'dataframe with multiindex' you can't force that behavior in the stubs. Do you see what I mean?
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.
One possible solution would be to only allow rename(column=d), where d is a dictionary containing tuples as keys and values of equal length, so that columns={(2, 1): "b"} will be forbidden.
However I couldn't work out how to implement this. For now, I'll leave it as it is.
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.
Thank you @loicdiridollou !
| # Apparently all of these calls are accepted by pandas | ||
| check(assert_type(df.rename(columns={None: "b"}), pd.DataFrame), pd.DataFrame) | ||
| check(assert_type(df.rename(columns={"": "b"}), pd.DataFrame), pd.DataFrame) | ||
| check(assert_type(df.rename(columns={(2, 1): "b"}), pd.DataFrame), pd.DataFrame) |
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.
One possible solution would be to only allow rename(column=d), where d is a dictionary containing tuples as keys and values of equal length, so that columns={(2, 1): "b"} will be forbidden.
However I couldn't work out how to implement this. For now, I'll leave it as it is.
assert_type()to assert the type of any return valuePR replaces the
DataFrame.renamewhen using a multi index in the replacer while the dataframe only hasIndex.