BUG: DataFrame doesn't hold _metadata when sliced by slice instance · Issue #9776 · pandas-dev/pandas (original) (raw)

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'