Skip to content

Commit 54caed3

Browse files
Fixes GH11698. added default value of mask and a test case.
1 parent e838266 commit 54caed3

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/source/whatsnew/v0.18.0.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ Bug Fixes
108108

109109

110110

111-
111+
- Bug in ``Timedelta.round`` with negative values (:issue:`11690`)
112112
- Bug in ``.loc`` against ``CategoricalIndex`` may result in normal ``Index`` (:issue:`11586`)
113113
- Bug groupby on tz-aware data where selection not returning ``Timestamp`` (:issue:`11616`)
114114
- Bug in timezone info lost when broadcasting scalar datetime to ``DataFrame`` (:issue:`11682`)
115+
116+
- Bug in ``.loc`` result with duplicated key may have ``Index`` with incorrect dtype (:issue:`11497`)
117+
118+
- Bug in ``df.replace`` while replacing value in mixed datatype Dataframe (:issue:`11698`)
119+

pandas/core/internals.py

+1
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ def replace(self, to_replace, value, inplace=False, filter=None,
588588
compatibility."""
589589

590590
original_to_replace = to_replace
591+
mask = isnull(self.values)
591592

592593
# try to replace, if we raise an error, convert to ObjectBlock and retry
593594
try:

pandas/tests/test_frame.py

+7
Original file line numberDiff line numberDiff line change
@@ -9666,6 +9666,13 @@ def test_replace(self):
96669666
df = DataFrame(index=['a', 'b'])
96679667
assert_frame_equal(df, df.replace(5, 7))
96689668

9669+
# GH 11698
9670+
# test for mixed data types.
9671+
df = pd.DataFrame([('-', pd.to_datetime('20150101')), ('a', pd.to_datetime('20150102'))])
9672+
df1 = df.replace('-', np.nan)
9673+
expected_df = pd.DataFrame([(np.nan, pd.to_datetime('20150101')), ('a', pd.to_datetime('20150102'))])
9674+
assert_frame_equal(df1, expected_df)
9675+
96699676
def test_replace_list(self):
96709677
obj = {'a': list('ab..'), 'b': list('efgh'), 'c': list('helo')}
96719678
dfobj = DataFrame(obj)

0 commit comments

Comments
 (0)