dalejung / pandas-composition

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

required __init__ args currently fail on wrapping #10

Closed dalejung closed 11 years ago

dalejung commented 11 years ago

Support init params for things like series + 1. While metadata propogates, currently (2013/07/01) wrapping fails because it calls the constructor instead of calling .view

        class SubSeries(UserSeries):
            def __init__(self, *args, **kwargs):
                bob = kwargs.pop('bob')
                self.bob = bob
                super(SubSeries, self).__init__(*args, **kwargs)

        ss = SubSeries(range(10), bob=123)
        assert ss.bob == 123
        test = ss + 1 # currently errors
        assert test.bob == 123
dalejung commented 11 years ago

Fixed by passing in the meta dictionary as keyword args to the subclass constructor. It's possible that most of these args aren't used by the constructor, which shouldn't be a problem as long as they don't clash with any DataFrame/Series constructor args.

There is an _init_args check that makes sure to only grab the appropriate arguments when calling the pandas constructors.