【发布时间】:2015-04-05 15:57:37
【问题描述】:
我正在尝试为我正在处理的一些自定义数据编写一个继承 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
我尝试使用谷歌搜索,但找不到有关此警告的有用描述。有人能帮我看看这个警告是什么意思吗?
【问题讨论】:
-
将有助于检查此错误是否特定于 pycharm,或者如果您尝试独立运行程序是否还会遇到一些相关错误
-
无法在 Python 2 或 Python 3 下复制此问题。也许您的代码的其他部分会触发该问题,但不仅仅是
DataFrame的这种简单的子类化。 -
是的,我在 SO 上发现了更多关于子类化
DataFrame的帖子。可能是因为这个 -
@uday,您找到发生这种情况的原因了吗?我在 python 2.7 中的继承类中也有同样的警告,但我没有找到如何使它正确。
-
@SecerH.,不,我没有。但我最终编写了自己的 DataFrame 类,它有一个 Pandas DataFrame 作为一个字段,然后在新类中,我重写了很多 Pandas 功能,以将其自定义为类似于 R 的工作方式(并使其在一些地区)。这样我的类可以被继承,我什至编写了一些继承这个类的子类,并根据需要具有额外的自定义功能。花了我好一阵子。如果你想做同样的事情,你可以编写自己的
__getitem__、__setitem__、__dir__、__getattr__方法等。
标签: python-3.x pandas