Skip to content

Subclassing not working as expected #11559

Closed
@rserbitar

Description

@rserbitar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugCompatpandas objects compatability with Numpy or Python functionsIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions