Skip to content

Commit

Permalink
REGR: replace replacing wrong values with inplace and datetime (#48866)
Browse files Browse the repository at this point in the history
* REGR: replace replacing wrong values with inplace and datetime

* Fix arrow

* Refactor
  • Loading branch information
phofl committed Sep 29, 2022
1 parent 8f26ab7 commit 3cfc81c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Fixed regressions
- Fixed performance regression in :func:`factorize` when ``na_sentinel`` is not ``None`` and ``sort=False`` (:issue:`48620`)
- 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`)
- Fixed regression in :func:`to_datetime` when ``arg`` was a date string with nanosecond and ``format`` contained ``%f`` would raise a ``ValueError`` (:issue:`48767`)
- Fixed regression in :meth:`DataFrame.fillna` replacing wrong values for ``datetime64[ns]`` dtype and ``inplace=True`` (:issue:`48863`)
- Fixed :meth:`.DataFrameGroupBy.size` not returning a Series when ``axis=1`` (:issue:`48738`)
- Fixed Regression in :meth:`DataFrameGroupBy.apply` when user defined function is called on an empty dataframe (:issue:`47985`)

Expand Down
2 changes: 2 additions & 0 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,8 @@ def putmask(self, mask, new) -> list[Block]:
mask = extract_bool_array(mask)

values = self.values
if values.ndim == 2:
values = values.T

orig_new = new
orig_mask = mask
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/frame/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
TimedeltaIndex,
Timestamp,
date_range,
to_datetime,
)
import pandas._testing as tm
from pandas.tests.frame.common import _check_mixed_float
Expand Down Expand Up @@ -682,6 +683,18 @@ def test_fillna_with_columns_and_limit(self):
tm.assert_frame_equal(result, expected)
tm.assert_frame_equal(result2, expected2)

def test_fillna_datetime_inplace(self):
# GH#48863
df = DataFrame(
{
"date1": to_datetime(["2018-05-30", None]),
"date2": to_datetime(["2018-09-30", None]),
}
)
expected = df.copy()
df.fillna(np.nan, inplace=True)
tm.assert_frame_equal(df, expected)

def test_fillna_inplace_with_columns_limit_and_value(self):
# GH40989
df = DataFrame(
Expand Down

0 comments on commit 3cfc81c

Please sign in to comment.