-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: Fix regression RecursionError when replacing numeric scalar with None #48234
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
Changes from 3 commits
205c0f0
18b4b92
1d1e98c
2402196
a71367d
2735ec2
796b870
42b11cb
077cd93
f1cf6e8
d7c7a9e
0eb2b08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1496,6 +1496,14 @@ def test_replace_list_with_mixed_type( | |
result = obj.replace(box(to_replace), value) | ||
tm.assert_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("val", [2, np.nan, 2.0]) | ||
def test_replace_value_none_dtype_numeric(self, val): | ||
# GH#48231 | ||
df = DataFrame({"a": [1, val]}) | ||
result = df.replace(val, None) | ||
expected = DataFrame({"a": [1, np.nan]}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So just confirming this result shouldn't be this?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is really what we want... Wanted to check if ci passes like this and go from there Especially since this does not handle the dict case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. IMO if we go with the current result here, I think we should document that the original Anecdotally, I've definitely seen There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @mroeschke This would restore the 1.4.x behavior for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC we had special logic for the case where the user specifically wants to replace one NA-like value with another (in this case np.nan->None). The non-special logic would do something like:
which for float64 dtype would take the None back to np.nan, consistent with what we do with every other setitem-like method. But in this case it is what the user specifically doesn't want. Not sure if this is helpful, but there it is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this would make more sense imo too, but would break previous behavior and fail a couple of tests too |
||
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
class TestDataFrameReplaceRegex: | ||
@pytest.mark.parametrize( | ||
|
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.
Guess we should move to 1.5.2 now
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.
Done