-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fix behavior of replace_list with mixed types. #40555
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 all commits
b035dd1
fddddf6
5f52f01
71dd789
18d2b79
4422cef
760f2d5
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 |
---|---|---|
|
@@ -1428,6 +1428,25 @@ def test_replace_bytes(self, frame_or_series): | |
obj = obj.replace({None: np.nan}) | ||
tm.assert_equal(obj, expected) | ||
|
||
@pytest.mark.parametrize( | ||
"data, to_replace, value, expected", | ||
[ | ||
([1], [1.0], [0], [0]), | ||
simonjayhawkins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
([1], [1], [0], [0]), | ||
([1.0], [1.0], [0], [0.0]), | ||
([1.0], [1], [0], [0.0]), | ||
], | ||
) | ||
@pytest.mark.parametrize("box", [list, tuple, np.array]) | ||
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. Would it be possible to test 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. That would fail. EA is not a documented allowed type for the Any container, even a list, with numpy scalars will still fail. This is a fix for a specific case for an arguably incorrect usage without a perf hit for correct usage. |
||
def test_replace_list_with_mixed_type( | ||
self, data, to_replace, value, expected, box, frame_or_series | ||
): | ||
# GH#40371 | ||
obj = frame_or_series(data) | ||
expected = frame_or_series(expected) | ||
result = obj.replace(box(to_replace), value) | ||
tm.assert_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.
I could maybe change this to a simple
isinstance(src_list, np.array)