1

I have

class MySeries(pd.Series):
    _metadata = [_md]

    def __init__(self, *args, **kwargs):
        md = kwargs.pop('md', None)  #md is series
        super(TimeSeries, self).__init__(*args, **kwargs)
        if md is not None:
            try:
                self._md = self._md.append(md)     
            except AttributeError:
                self._md = md

    @property
    def _constructor(self):
        return MySeries

class MyFrame(pd.DataFrame):

    @property
    def _constructor(self):
        return MyFrame    

    @property
    def _constructor_sliced(self):
        return MySeries


md_a = pd.Series(...some content...)
md_b = pd.Series(...some other content...)
a = MySeries(...some a content..., md=md_a)
b = MySeries(...some b content..., md=md_b)

Tim now everything is fine: a._md gives the content of md_a. So does b.

No I create my MyFrame with :

f = MyFrame([a,b]).T

or

f = SecuritiesFrame()
f = pd.concat((f, a, b), axis=1)

Now I try to get the metadata:

f.iloc[:,1]._md

I get an AttributeError: 'MyFrame' object has no attribute '_md' as the metadata is not propagated.

Is this a normal behavior or am I overseeing something? Do I have to track the metadata myself separately in my subclass of DataFrame which would be very inconvenient.

EdChum
  • 376,765
  • 198
  • 813
  • 562
leofields
  • 659
  • 1
  • 7
  • 12
  • metadata is not copied unfortunately you'd have to keep track of this yourself – EdChum Jan 14 '16 at 15:13
  • Any worthwhile example upon which I could build apart from geopandas? – leofields Jan 14 '16 at 15:22
  • [This answer](http://stackoverflow.com/a/22161058/4077912) might help... – Primer Jan 14 '16 at 19:32
  • Take a look at the `__finalize__` method. It copies metadata for some, but not all situations. I'm working on something similar right now and investigating fow to override it to handle what I want. – Mike Selik Apr 19 '20 at 21:18

0 Answers0