Skip to content

BUG: DataFrame doesn't hold _metadata when sliced by slice instance #9776

Closed
@sinhrks

Description

@sinhrks
import pandas as pd


class TestDataFrame(pd.DataFrame):

    _metadata = ['testattr']

    @property
    def _constructor(self):
        return TestDataFrame

df = TestDataFrame({0: [1, 2, 3], 1: [1, 2, 3]})
df.testattr = 'XXX'
df.testattr
# XXX

# Using list is OK
df.iloc[[0, 1], :].testattr
# XXX

# Using slice is NG
df.iloc[0:1, :].testattr
# AttributeError: 'TestDataFrame' object has no attribute 'testattr'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions