pandas 禁用Pylint无成员-特定库的E1101错误

ymzxtsji  于 2023-09-29  发布在  其他
关注(0)|答案(3)|浏览(89)

有没有一种方法可以隐藏从特定库创建的对象的E1101错误?我们的大型存储库中到处都是pandas创建的各种对象周围的#pylint: disable=E1101
例如,Pylint将在以下代码中抛出 no member 错误:

import pandas.io.data
import pandas as pd
spy = pandas.io.data.DataReader("SPY", "yahoo")
spy.to_csv("test.csv")
spy = pd.read_csv("test.csv")
close_px = spy.ix["2012":]

它将出现以下错误:

E:  6,11: Instance of 'tuple' has no 'ix' member (no-member)
E:  6,11: Instance of 'TextFileReader' has no 'ix' member (no-member)
qxsslcnc

qxsslcnc1#

您可以使用generated-members选项将其属性标记为动态生成。
例如,对于Pandas:

generated-members=pandas.*
shyt4zoc

shyt4zoc2#

我尝试忽略NumPy中的错误时失败了,直到我尝试:

generated-members=np.*

因为我和大多数人一样

import numpy as np

由于generated-members接受一个列表,所以可以这样做:

generated-members=numpy.*,np.*
niknxzdl

niknxzdl3#

  • 在carabas的回答之上的其他信息:*

您将在.pylintrcTYPECHECK部分找到generated-members
下面是默认的一个:

[TYPECHECK]
…
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 when accessed.
generated-members=REQUEST,acl_users,aq_parent

请注意,有关抑制E0201的注解不完整。
因此,您必须将其更新为:

# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E0201 or E1101 when accessed.
generated-members=REQUEST,acl_users,aq_parent,pandas.*

相关问题