Skip to content
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

Preserve subclass family on reshape operations #15563

Closed
delgadom opened this issue Mar 4, 2017 · 0 comments · Fixed by #18929
Closed

Preserve subclass family on reshape operations #15563

delgadom opened this issue Mar 4, 2017 · 0 comments · Fixed by #18929
Labels
API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode Subclassing Subclassing pandas objects
Milestone

Comments

@delgadom
Copy link

delgadom commented Mar 4, 2017

Subclassed Series and DataFrames with custom _constructor, _constructor_sliced, and _constructor_expanddim methods return pandas Series and DataFrame objects on reshape operations:

>>> import numpy as np, pandas as pd
>>> import pandas.util.testing as tm
>>> df = tm.SubclassedDataFrame(np.random.random((4,5)))
>>> df
          0         1         2         3         4
0  0.151944  0.948561  0.639122  0.718071  0.296193
1  0.004606  0.978378  0.827614  0.479320  0.495945
2  0.158874  0.535476  0.173194  0.065292  0.365851
3  0.772392  0.105038  0.671064  0.164165  0.795803
>>> type(df)
<class 'pandas.util.testing.SubclassedDataFrame'>

Slicing operations use _constructor_sliced:

>>> type(df[0])
<class 'pandas.util.testing.SubclassedSeries'>

Reshape operations return regular pandas objects:

>>> type(df.stack())
<class 'pandas.core.series.Series'>

It would be great if this returned a SublcassedSeries. Same goes for unstack and pivot.

@delgadom delgadom changed the title Preserve subclass family on reshape operations (e.g. stack/unstack) Preserve subclass family on reshape operations Mar 4, 2017
@delgadom delgadom mentioned this issue Mar 4, 2017
4 tasks
@jreback jreback added API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Mar 4, 2017
@jreback jreback added this to the Next Major Release milestone Mar 7, 2017
@jreback jreback modified the milestones: Next Major Release, 0.23.0 Dec 26, 2017
@jorisvandenbossche jorisvandenbossche added the Subclassing Subclassing pandas objects label Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode Subclassing Subclassing pandas objects
Projects
None yet
3 participants