-
-
Notifications
You must be signed in to change notification settings - Fork 154
Fix: DataFrame.replace incompatible with type "dict[str, dict[int, int]]" #1164
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
b05d3d1 to
694d40d
Compare
pandas-stubs/core/frame.pyi
Outdated
| to_replace: ReplaceValue | Mapping[Hashable, ReplaceValue] = ..., | ||
| value: ReplaceValue | Mapping[Hashable, ReplaceValue] = ..., | ||
| to_replace: ReplaceValue | Mapping[HashableT2, ReplaceValue] = ..., | ||
| value: ReplaceValue | Mapping[HashableT2, ReplaceValue] = ..., |
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.
should be HashableT3 since it might not be the same type as HashableT2.
Same here and throughout
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've made the change, but I think if someone writes df.replace({'a': 1}, {0: 9}) then that's likely a user error. Though there's likely some valid usage I can't think, so perhaps best to err on the side of not letting false positives through
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've made the change, but I think if someone writes
df.replace({'a': 1}, {0: 9})then that's likely a user error. Though there's likely some valid usage I can't think, so perhaps best to err on the side of not letting false positives through
Yes, I agree. While this is valid:
>>> import pandas as pd
>>> df = pd.DataFrame([["a", 1], ["b", 2]], columns=["ab", "num"])
>>> df
ab num
0 a 1
1 b 2
>>> df.replace({"a":"foo", 2: 20})
ab num
0 foo 1
1 b 20it's not a great idea to be mixing types in one statement. With the stubs, I try to support "normal" usage of pandas. Otherwise, the stubs get too wide and don't catch common errors.
Dr-Irv
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.
Looks good. When green, change from draft and ping me and I'll approve and merge
Dr-Irv
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.
thanks @MarcoGorelli
assert_type()to assert the type of any return valuecloses #1161