I saw this behaviour and I don't know if this is a bug or feature. I don't have much experience with directly inheriting from pandas.DataFrame as I've always preferred aggregation rather than inheritance there. A working sample is pasted below. Notice how df.astype(dtypes) changes the type to pandas.DataFrame. Any suggestions if this is intended behaviour?
import pandas as pd
class DF(pd.DataFrame):
@property
def _constructor(self):
return self.__class__
df = DF({
'A': [1,2,3],
'B': [10,20,30],
'C': [100,200,300],
}) # Type is DF
a = df['A'] # type is Series
ab = df[['A', 'B']] # type is DF
dtypes = {'A': 'float64', 'B': 'float64', 'C': 'float64'}
x = df.astype(dtypes)
type(x) # type is pd.DataFrame
Regards,
Simeon