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

Subclassing not working as expected #11559

Closed
rserbitar opened this issue Nov 9, 2015 · 3 comments
Closed

Subclassing not working as expected #11559

rserbitar opened this issue Nov 9, 2015 · 3 comments
Labels
Bug Compat pandas objects compatability with Numpy or Python functions Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@rserbitar
Copy link

Running the code:

import pandas

class SubclassedSeries(pandas.Series):
    @property
    def _constructor(self):
        return SubclassedSeries

    @property
    def _constructor_expanddim(self):
        return SubclassedDataFrame

    def c(self):
        return 1

class SubclassedDataFrame(pandas.DataFrame):
    @property
    def _constructor(self):
        return SubclassedDataFrame

    @property
    def _constructor_sliced(self):
        return SubclassedSeries


b = SubclassedDataFrame([[1,2,3,4],[2,3,4,5]])
print(b[0].c())

works as expected.

However running:

print(b.ix[1].c())

throws an exception as:

b.ix[1]

returns a Series instance instead of an SublcassedSeries instance as expected.

@jreback
Copy link
Contributor

jreback commented Nov 9, 2015

ok, subclassing is not recommended, see docs here, but would take a pull-request to fully test out the indexers (as this is not currently done).

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Compat pandas objects compatability with Numpy or Python functions Difficulty Intermediate labels Nov 9, 2015
@jreback jreback added this to the Next Major Release milestone Nov 9, 2015
@jreback jreback modified the milestones: 0.18.1, Next Major Release Feb 18, 2016
@sinhrks
Copy link
Member

sinhrks commented Apr 15, 2016

This is already fixed on master (maybe by #12787). Needs tests though.

@kielpins-hp
Copy link

The lack of subclassing makes it difficult and/or fragile to extend the package in any way. It's really unfortunate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Compat pandas objects compatability with Numpy or Python functions Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants