Skip to content

Commit 2f55283

Browse files
authored
call __finalize__ in more methods (#37186)
1 parent 8dcf9b1 commit 2f55283

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

doc/source/whatsnew/v1.2.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ Other
524524
- Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` incorrectly raising ``AssertionError`` instead of ``ValueError`` when invalid parameter combinations are passed (:issue:`36045`)
525525
- Bug in :meth:`DataFrame.replace` and :meth:`Series.replace` with numeric values and string ``to_replace`` (:issue:`34789`)
526526
- Fixed bug in metadata propagation incorrectly copying DataFrame columns as metadata when the column name overlaps with the metadata name (:issue:`37037`)
527-
- Fixed metadata propagation in the :class:`Series.dt` and :class:`Series.str` accessors (:issue:`28283`)
527+
- Fixed metadata propagation in the :class:`Series.dt` and :class:`Series.str` accessors and :class:`DataFrame.duplicated` and ::class:`DataFrame.stack` methods (:issue:`28283`)
528528
- Bug in :meth:`Index.union` behaving differently depending on whether operand is a :class:`Index` or other list-like (:issue:`36384`)
529529
- Passing an array with 2 or more dimensions to the :class:`Series` constructor now raises the more specific ``ValueError``, from a bare ``Exception`` previously (:issue:`35744`)
530530

pandas/core/frame.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -5286,7 +5286,8 @@ def f(vals):
52865286
labels, shape = map(list, zip(*map(f, vals)))
52875287

52885288
ids = get_group_index(labels, shape, sort=False, xnull=False)
5289-
return self._constructor_sliced(duplicated_int64(ids, keep), index=self.index)
5289+
result = self._constructor_sliced(duplicated_int64(ids, keep), index=self.index)
5290+
return result.__finalize__(self, method="duplicated")
52905291

52915292
# ----------------------------------------------------------------------
52925293
# Sorting
@@ -7096,9 +7097,11 @@ def stack(self, level=-1, dropna=True):
70967097
from pandas.core.reshape.reshape import stack, stack_multiple
70977098

70987099
if isinstance(level, (tuple, list)):
7099-
return stack_multiple(self, level, dropna=dropna)
7100+
result = stack_multiple(self, level, dropna=dropna)
71007101
else:
7101-
return stack(self, level, dropna=dropna)
7102+
result = stack(self, level, dropna=dropna)
7103+
7104+
return result.__finalize__(self, method="stack")
71027105

71037106
def explode(
71047107
self, column: Union[str, Tuple], ignore_index: bool = False

pandas/tests/generic/test_finalize.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@
115115
(pd.DataFrame, frame_data, operator.methodcaller("notnull")),
116116
(pd.DataFrame, frame_data, operator.methodcaller("dropna")),
117117
(pd.DataFrame, frame_data, operator.methodcaller("drop_duplicates")),
118-
pytest.param(
119-
(pd.DataFrame, frame_data, operator.methodcaller("duplicated")),
120-
marks=not_implemented_mark,
121-
),
118+
(pd.DataFrame, frame_data, operator.methodcaller("duplicated")),
122119
(pd.DataFrame, frame_data, operator.methodcaller("sort_values", by="A")),
123120
(pd.DataFrame, frame_data, operator.methodcaller("sort_index")),
124121
(pd.DataFrame, frame_data, operator.methodcaller("nlargest", 1, "A")),
@@ -169,10 +166,7 @@
169166
),
170167
marks=not_implemented_mark,
171168
),
172-
pytest.param(
173-
(pd.DataFrame, frame_data, operator.methodcaller("stack")),
174-
marks=not_implemented_mark,
175-
),
169+
(pd.DataFrame, frame_data, operator.methodcaller("stack")),
176170
pytest.param(
177171
(pd.DataFrame, frame_data, operator.methodcaller("explode", "A")),
178172
marks=not_implemented_mark,

0 commit comments

Comments
 (0)