Skip to content

REGR: replace replacing wrong values with inplace and datetime #48866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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