Pandas DataFrame Object Inheritance or Object Use?

前端 未结 2 1904
走了就别回头了
走了就别回头了 2020-12-16 22:19

I am building a library for working with very specific structured data and I am building my infrastructure on top of Pandas. Currently I am writing a bunch of different data

2条回答
  •  误落风尘
    2020-12-16 23:06

    I would avoid subclassing DataFrame, because many of the DataFrame methods will return a new DataFrame and not another instance of your CTMatrix object.

    There are a few of open issues on GitHub around this e.g.:

    • https://github.com/pydata/pandas/issues/60

    • https://github.com/pydata/pandas/issues/2485

    More generally, this is a question of composition vs inheritance. I would be especially wary of benefit #2. It might seem great now, but unless you are keeping a close eye on updates to Pandas (and it is a fast moving target), you can easily end up with unexpected consequences and your code will end up intertwined with Pandas.

提交回复
热议问题