dalejung / pandas-composition

Pandas Composition/Inheritance
MIT License
9 stars 0 forks source link

Monkey patched methods on base pandas methods have wrong type(self) #19

Open dalejung opened 11 years ago

dalejung commented 11 years ago
        def type_method(self):
            return type(self)

        pd.Series.type_method = type_method

        class SubSeries(UserSeries):
            pass

        s = SubSeries(range(10))
        t = s.type_method()
        assert t is SubSeries # fails, t is pd.Series

This is because we call pget to get the method which grabs the method bound to a pd.Series.

SubSeries.type_method(s) works correctly because it's a method bound to SubSeries

dalejung commented 11 years ago

This is a thorny issue. Conceptually speaking, since UserFrame isn't a proper subclass and is instead this quasi-composition object, this probably shouldn't matter.

The issue I had was with ts-charting where I put in a check for an attr that wouldn't exist in normal pandas object. So perhaps I should address the issue there and just monkey patch it to UserFrame