8000 BUG: Fix replace for different dtype equal value by dsaxton · Pull Request #34878 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix replace for different dtype equal value #34878

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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Tests
  • Loading branch information
dsaxton committed Jun 20, 2020
commit 47c83f9213816804d0c401bf4b6e7b42c3a9048b
6 changes: 6 additions & 0 deletions pandas/tests/frame/methods/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1403,3 +1403,9 @@ def test_replace_with_duplicate_columns(self, replacement):
result["B"] = result["B"].replace(7, replacement)

tm.assert_frame_equal(result, expected)

def test_replace_equal_value_different_dtype(self):
df = pd.DataFrame([1, 2, 3], dtype=int)
result = df.replace(1.0, 0)
expected = pd.DataFrame([0, 2, 3], dtype=int)
tm.assert_frame_equal(result, expected)
6 changes: 6 additions & 0 deletions pandas/tests/series/methods/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,9 @@ def test_replace_extension_other(self):
# https://github.com/pandas-dev/pandas/issues/34530
ser = pd.Series(pd.array([1, 2, 3], dtype="Int64"))
ser.replace("", "") # no exception

def test_replace_equal_value_different_dtype(self):
ser = pd.Series([1, 2, 3], dtype=int)
result = ser.replace(1.0, 0)
expected = pd.Series([0, 2, 3], dtype=int)
tm.assert_series_equal(result, expected)
0