def test___init__(self): """ Test that supermeta metaclass acts like a super parent to both UserSeries and UserFrame """ class InitSeries(UserSeries): def __init__(self, *args, **kwargs): # required bob = kwargs.pop("bob") self.bob = bob super(InitSeries, self).__init__(*args, **kwargs) class InitFrame(UserFrame): def __init__(self, *args, **kwargs): # required bob = kwargs.pop("bob") self.bob = bob super(InitFrame, self).__init__(*args, **kwargs) s = InitSeries(list(range(10)), name="hello", bob=123) assert s.bob == 123 df = tm.makeDataFrame() fr = InitFrame(df, bob="woot") assert fr.bob == "woot"
def test_supermeta(self): """ Test that supermeta metaclass acts like a super parent to both UserSeries and UserFrame """ class CommonBase(composition.PandasSuperMeta): """ Test common base """ _bob = object() @property def bob(self): return self._bob class CommonSeries(UserSeries, metaclass=CommonBase): pass class CommonFrame(UserFrame, metaclass=CommonBase): pass bob = CommonBase._bob s = CommonSeries(list(range(10))) assert s.ix[3] == 3 tm.assert_almost_equal(s, list(range(10))) assert s.bob is bob s._bob = 123 assert s.bob == 123 df = tm.makeDataFrame() fr = CommonFrame(df) tm.assert_almost_equal(fr.values, df.values) assert fr.bob is bob assert fr.tail().bob is bob
def test___init__(self): """ Test that supermeta metaclass acts like a super parent to both UserSeries and UserFrame """ class InitSeries(UserSeries): def __init__(self, *args, **kwargs): # required bob = kwargs.pop('bob') self.bob = bob super(InitSeries, self).__init__(*args, **kwargs) class InitFrame(UserFrame): def __init__(self, *args, **kwargs): # required bob = kwargs.pop('bob') self.bob = bob super(InitFrame, self).__init__(*args, **kwargs) s = InitSeries(list(range(10)), name='hello', bob=123) assert s.bob == 123 df = tm.makeDataFrame() fr = InitFrame(df, bob='woot') assert fr.bob == 'woot'
def test_supermeta(self): """ Test that supermeta metaclass acts like a super parent to both UserSeries and UserFrame """ class CommonBase(composition.PandasSuperMeta): """ Test common base """ _bob = object() @property def bob(self): return self._bob class CommonSeries(UserSeries): __metaclass__ = CommonBase class CommonFrame(UserFrame): __metaclass__ = CommonBase bob = CommonBase._bob s = CommonSeries(range(10)) assert s.ix[3] == 3 tm.assert_almost_equal(s, range(10)) assert s.bob is bob s._bob = 123 assert s.bob == 123 df = tm.makeDataFrame() fr = CommonFrame(df) tm.assert_almost_equal(fr, df) assert fr.bob is bob assert fr.tail().bob is bob