Skip to content

Commit 0cc664f

Browse files
committed
call finalize in DataFrame.count
1 parent b1747d2 commit 0cc664f

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

pandas/core/frame.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8571,7 +8571,8 @@ def count(self, axis=0, level=None, numeric_only=False):
85718571
"""
85728572
axis = self._get_axis_number(axis)
85738573
if level is not None:
8574-
return self._count_level(level, axis=axis, numeric_only=numeric_only)
8574+
result = self._count_level(level, axis=axis, numeric_only=numeric_only)
8575+
return result.__finalize__(self, method="count")
85758576

85768577
if numeric_only:
85778578
frame = self._get_numeric_data()
@@ -8594,7 +8595,7 @@ def count(self, axis=0, level=None, numeric_only=False):
85948595
counts, index=frame._get_agg_axis(axis)
85958596
)
85968597

8597-
return result.astype("int64")
8598+
return result.astype("int64").__finalize__(self, method="count")
85988599

85998600
def _count_level(self, level, axis=0, numeric_only=False):
86008601
if numeric_only:

pandas/tests/generic/test_finalize.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,8 @@
238238
),
239239
marks=not_implemented_mark,
240240
),
241-
pytest.param(
242-
(pd.DataFrame, frame_data, operator.methodcaller("count")),
243-
marks=not_implemented_mark,
244-
),
245-
pytest.param(
246-
(pd.DataFrame, frame_mi_data, operator.methodcaller("count", level="A")),
247-
marks=not_implemented_mark,
248-
),
241+
(pd.DataFrame, frame_data, operator.methodcaller("count")),
242+
(pd.DataFrame, frame_mi_data, operator.methodcaller("count", level="A")),
249243
pytest.param(
250244
(pd.DataFrame, frame_data, operator.methodcaller("nunique")),
251245
marks=not_implemented_mark,

0 commit comments

Comments
 (0)