Skip to content

Fix to BUG GH11698. added default value of mask #11715

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion doc/source/whatsnew/v0.18.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ Bug Fixes




- Bug in ``Timedelta.round`` with negative values (:issue:`11690`)
- Bug in ``.loc`` against ``CategoricalIndex`` may result in normal ``Index`` (:issue:`11586`)
- Bug groupby on tz-aware data where selection not returning ``Timestamp`` (:issue:`11616`)
- Bug in timezone info lost when broadcasting scalar datetime to ``DataFrame`` (:issue:`11682`)

- Bug in ``.loc`` result with duplicated key may have ``Index`` with incorrect dtype (:issue:`11497`)

- Bug in ``df.replace`` while replacing value in mixed datatype Dataframe (:issue:`11698`)

1 change: 1 addition & 0 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ def replace(self, to_replace, value, inplace=False, filter=None,
compatibility."""

original_to_replace = to_replace
mask = isnull(self.values)

# try to replace, if we raise an error, convert to ObjectBlock and retry
try:
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9666,6 +9666,13 @@ def test_replace(self):
df = DataFrame(index=['a', 'b'])
assert_frame_equal(df, df.replace(5, 7))

# GH 11698
# test for mixed data types.
df = pd.DataFrame([('-', pd.to_datetime('20150101')), ('a', pd.to_datetime('20150102'))])
df1 = df.replace('-', np.nan)
expected_df = pd.DataFrame([(np.nan, pd.to_datetime('20150101')), ('a', pd.to_datetime('20150102'))])
assert_frame_equal(df1, expected_df)

def test_replace_list(self):
obj = {'a': list('ab..'), 'b': list('efgh'), 'c': list('helo')}
dfobj = DataFrame(obj)
Expand Down