Skip to content

Commit 8ec8487

Browse files
varunkumar-devjreback
authored andcommitted
Fixes GH11698. added default value of mask and a test case. #11698
1 parent 7d2022a commit 8ec8487

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/source/whatsnew/v0.18.0.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,13 @@ Bug Fixes
161161

162162

163163

164-
- Bug in ``Timedelta.round`` with negative values (:issue:`11690`)
165-
166164

167165

168166

169167

170168

171169

170+
- Bug in ``Timedelta.round`` with negative values (:issue:`11690`)
172171
- Bug in ``.loc`` against ``CategoricalIndex`` may result in normal ``Index`` (:issue:`11586`)
173172

174173

@@ -194,3 +193,5 @@ Bug Fixes
194193

195194
- Bug in ``.loc`` result with duplicated key may have ``Index`` with incorrect dtype (:issue:`11497`)
196195
- Bug in ``pd.rolling_median`` where memory allocation failed even with sufficient memory (:issue:`11696`)
196+
197+
- Bug in ``df.replace`` while replacing value in mixed dtype ``Dataframe`` (:issue:`11698`)

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)