Skip to content

Commit e2d0288

Browse files
authored
Fixed metadata propagation in Dataframe.apply (issue #28283) (#44041)
1 parent 66a1e92 commit e2d0288

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ Reshaping
609609
- Bug in :func:`concat` which ignored the ``sort`` parameter (:issue:`43375`)
610610
- Fixed bug in :func:`merge` with :class:`MultiIndex` as column index for the ``on`` argument returning an error when assigning a column internally (:issue:`43734`)
611611
- Bug in :func:`crosstab` would fail when inputs are lists or tuples (:issue:`44076`)
612+
- Fixed metadata propagation in :meth:`Dataframe.apply` method, consequently fixing the same issue for :meth:`Dataframe.transform`, :meth:`Dataframe.nunique` and :meth:`Dataframe.mode` (:issue:`28283`)
612613

613614
Sparse
614615
^^^^^^

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8872,7 +8872,7 @@ def apply(
88728872
args=args,
88738873
kwargs=kwargs,
88748874
)
8875-
return op.apply()
8875+
return op.apply().__finalize__(self, method="apply")
88768876

88778877
def applymap(
88788878
self, func: PythonFuncType, na_action: str | None = None, **kwargs

pandas/tests/generic/test_finalize.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@
233233
),
234234
pytest.param(
235235
(pd.DataFrame, frame_data, operator.methodcaller("nunique")),
236-
marks=not_implemented_mark,
237236
),
238237
pytest.param(
239238
(pd.DataFrame, frame_data, operator.methodcaller("idxmin")),
@@ -245,6 +244,9 @@
245244
),
246245
pytest.param(
247246
(pd.DataFrame, frame_data, operator.methodcaller("mode")),
247+
),
248+
pytest.param(
249+
(pd.Series, [0], operator.methodcaller("mode")),
248250
marks=not_implemented_mark,
249251
),
250252
pytest.param(
@@ -467,12 +469,10 @@
467469
frame_mi_data,
468470
operator.methodcaller("transform", lambda x: x - x.min()),
469471
),
470-
marks=not_implemented_mark,
471472
),
472473
(pd.Series, ([1],), operator.methodcaller("apply", lambda x: x)),
473474
pytest.param(
474475
(pd.DataFrame, frame_mi_data, operator.methodcaller("apply", lambda x: x)),
475-
marks=not_implemented_mark,
476476
),
477477
# Cumulative reductions
478478
(pd.Series, ([1],), operator.methodcaller("cumsum")),

0 commit comments

Comments
 (0)