构建继承pandas DataFrame的类

时间:2015-04-05 15:57:38

标签: python-3.x pandas

我正在尝试编写一个继承了pandas'我正在处理的一些自定义数据的DataFrame类。

class EquityDataFrame(DataFrame):
    def __init__(self, *args, **kwargs):
        DataFrame.__init__(self, *args, **kwargs)

    def myfunc1(self,...)
        ... # does something

    def myfunc2(self, ...)
        ... # does something

在PyCharm中,我收到了类EquityDataFrame名称的以下警告:

Class EquityDataFrame must implement all abstract methods 

This inspection detects when there aren't all abstract properties/methods defined in the subclass

我尝试使用Google搜索,但我无法找到有关此警告的有用说明。有人能帮助我这个警告意味着什么吗?

2 个答案:

答案 0 :(得分:1)

找了6年,pylint给了我答案:
[W0223(abstract-method), CustomDataFrame] Method '_constructor_expanddim' is abstract in class 'DataFrame' but is not overridden

并且确实实施

@property
def _constructor_expanddim(self) -> Type["CustomDataFrame"]:
    raise NotImplementedError("Not supported for CustomDataFrames!")

使警告消失。

答案 1 :(得分:0)

尝试类似下面的内容

import pandas as pd

class MyDataframe(pd.DataFrame):

def __init__(self, *args, **kwargs):
    super(MyDataframe, self).__init__(*args, **kwargs)

@property
def function_1(self, x):


@property
def function_2(self):