Skip to content

REGR: DataFrame.replace when the replacement value was explicitly None #46404

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

Merged
merged 3 commits into from
Mar 19, 2022
Merged
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
Prev Previous commit
Merge remote-tracking branch 'upstream/main' into replace-list-with-N…
…one-value
  • Loading branch information
simonjayhawkins committed Mar 18, 2022
commit eba88214fafb648bb735abcae9d1b7d7b9a82b8c
15 changes: 0 additions & 15 deletions pandas/tests/frame/methods/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,21 +661,6 @@ def test_replace_simple_nested_dict_with_nonexistent_value(self):
result = df.replace({"col": {-1: "-", 1: "a", 4: "b"}})
tm.assert_frame_equal(expected, result)

def test_replace_numpy_nan(self, nulls_fixture):
# GH#45725 ensure numpy.nan can be replaced with all other null types
to_replace = np.nan
value = nulls_fixture
dtype = object
df = DataFrame({"A": [to_replace]}, dtype=dtype)
expected = DataFrame({"A": [value]}, dtype=dtype)

result = df.replace({to_replace: value}).astype(dtype=dtype)
tm.assert_frame_equal(result, expected)

# same thing but different calling convention
result = df.replace(to_replace, value).astype(dtype=dtype)
tm.assert_frame_equal(result, expected)

def test_replace_NA_with_None(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in all of the relevant examples the both the value being replaced and the replacement are NA. are these the only affected cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC for a list like to_replace None is treated explicitly at the moment, whereas if using a scalar None, the behavior is different in some cases. My understanding is that users are therefore using a dictionary to get the explicit replacement behavior. To make these consistent, we would need to deprecate this?

# gh-45601
df = DataFrame({"value": [42, None]}).astype({"value": "Int64"})
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.