Skip to content

df.iterrows() constructs Series instead of its proper subclass #13977

Closed
@kernc

Description

@kernc

Code Sample, a copy-pastable example if possible

import pandas as pd
import numpy as np


class SubclassedSeries(pd.Series):
    pass


class SubclassedDataFrame(pd.DataFrame):
    _constructor_sliced = SubclassedSeries


df = SubclassedDataFrame(np.random.random((3, 2))
i, row = next(df.iterrows())

assert isinstance(row, SubclassedSeries)  # fails

Expected Output

row would be of proper overriden _constructor_sliced type (i.e. SubclassedSeries).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions