Skip to content

Commit 96be757

Browse files
Backport PR #48866 on branch 1.5.x (REGR: replace replacing wrong values with inplace and datetime) (#48872)
Backport PR #48866: REGR: replace replacing wrong values with inplace and datetime Co-authored-by: Patrick Hoefler <[email protected]>
1 parent e656091 commit 96be757

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

doc/source/whatsnew/v1.5.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Fixed regressions
7777
- Fixed performance regression in :func:`factorize` when ``na_sentinel`` is not ``None`` and ``sort=False`` (:issue:`48620`)
7878
- Fixed regression causing an ``AttributeError`` during warning emitted if the provided table name in :meth:`DataFrame.to_sql` and the table name actually used in the database do not match (:issue:`48733`)
7979
- Fixed regression in :func:`to_datetime` when ``arg`` was a date string with nanosecond and ``format`` contained ``%f`` would raise a ``ValueError`` (:issue:`48767`)
80+
- Fixed regression in :meth:`DataFrame.fillna` replacing wrong values for ``datetime64[ns]`` dtype and ``inplace=True`` (:issue:`48863`)
8081
- Fixed :meth:`.DataFrameGroupBy.size` not returning a Series when ``axis=1`` (:issue:`48738`)
8182
- Fixed Regression in :meth:`DataFrameGroupBy.apply` when user defined function is called on an empty dataframe (:issue:`47985`)
8283
-

pandas/core/internals/blocks.py

+2
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,8 @@ def putmask(self, mask, new) -> list[Block]:
15021502
mask = extract_bool_array(mask)
15031503

15041504
values = self.values
1505+
if values.ndim == 2:
1506+
values = values.T
15051507

15061508
orig_new = new
15071509
orig_mask = mask

pandas/tests/frame/methods/test_fillna.py

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
TimedeltaIndex,
1414
Timestamp,
1515
date_range,
16+
to_datetime,
1617
)
1718
import pandas._testing as tm
1819
from pandas.tests.frame.common import _check_mixed_float
@@ -682,6 +683,18 @@ def test_fillna_with_columns_and_limit(self):
682683
tm.assert_frame_equal(result, expected)
683684
tm.assert_frame_equal(result2, expected2)
684685

686+
def test_fillna_datetime_inplace(self):
687+
# GH#48863
688+
df = DataFrame(
689+
{
690+
"date1": to_datetime(["2018-05-30", None]),
691+
"date2": to_datetime(["2018-09-30", None]),
692+
}
693+
)
694+
expected = df.copy()
695+
df.fillna(np.nan, inplace=True)
696+
tm.assert_frame_equal(df, expected)
697+
685698
def test_fillna_inplace_with_columns_limit_and_value(self):
686699
# GH40989
687700
df = DataFrame(

0 commit comments

Comments
 (0)