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

Comments

Projects
None yet
2 participants
@delgadom

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 from Preserve subclass family on reshape operations (e.g. stack/unstack) to Preserve subclass family on reshape operations Mar 4, 2017

@delgadom delgadom referenced this issue Mar 4, 2017

Closed

Subclassed reshape #15564

4 of 4 tasks complete

@jreback jreback added this to the Next Major Release milestone Mar 7, 2017

@delgadom delgadom referenced this issue Mar 11, 2017

Closed

Subclassed reshape clean #15655

4 of 4 tasks complete

@jreback jreback modified the milestones: Next Major Release, 0.23.0 Dec 26, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment