diff --git a/doc/source/whatsnew/v0.18.0.txt b/doc/source/whatsnew/v0.18.0.txt index d4ed68b9f4343..a20ca31dfbdc0 100644 --- a/doc/source/whatsnew/v0.18.0.txt +++ b/doc/source/whatsnew/v0.18.0.txt @@ -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`) + diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 1b08140ebec09..28c845f63f9d4 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -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: diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 5c4fa5a2e9c56..d60c5a4bd1e78 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -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)