Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bd6b395

Browse files
Emiliano Jordanjreback
Emiliano Jordan
authored andcommittedJan 24, 2020
BUG: Use self._constructor_sliced in df._reduce to respect subclassed… (#30945)
1 parent f5aa542 commit bd6b395

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed
 

‎doc/source/whatsnew/v1.1.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Groupby/resample/rolling
173173
Reshaping
174174
^^^^^^^^^
175175

176-
-
176+
- Bug effecting all numeric and boolean reduction methods not returning subclassed data type. (:issue:`25596`)
177177
- Bug in :meth:`DataFrame.pivot_table` when only MultiIndexed columns is set (:issue:`17038`)
178178
- Bug in :meth:`DataFrame.unstack` and :meth:`Series.unstack` can take tuple names in MultiIndexed data (:issue:`19966`)
179179
- Bug in :meth:`DataFrame.pivot_table` when ``margin`` is ``True`` and only ``column`` is defined (:issue:`31016`)

‎pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8013,7 +8013,7 @@ def _get_data(axis_matters):
80138013
result = coerce_to_dtypes(result, self.dtypes)
80148014

80158015
if constructor is not None:
8016-
result = Series(result, index=labels)
8016+
result = self._constructor_sliced(result, index=labels)
80178017
return result
80188018

80198019
def nunique(self, axis=0, dropna=True) -> Series:

‎pandas/tests/frame/test_subclass.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,17 @@ def strech(row):
557557
result = df.apply(lambda x: [1, 2, 3], axis=1)
558558
assert not isinstance(result, tm.SubclassedDataFrame)
559559
tm.assert_series_equal(result, expected)
560+
561+
def test_subclassed_numeric_reductions(self, all_numeric_reductions):
562+
# GH 25596
563+
564+
df = tm.SubclassedDataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
565+
result = getattr(df, all_numeric_reductions)()
566+
assert isinstance(result, tm.SubclassedSeries)
567+
568+
def test_subclassed_boolean_reductions(self, all_boolean_reductions):
569+
# GH 25596
570+
571+
df = tm.SubclassedDataFrame({"A": [1, 2, 3], "B": [4, 5, 6], "C": [7, 8, 9]})
572+
result = getattr(df, all_boolean_reductions)()
573+
assert isinstance(result, tm.SubclassedSeries)

0 commit comments

Comments
 (0)
Please sign in to comment.