43

Is there anyway to hide E1101 errors for objects that are created from a specific library? Our large repository is littered with #pylint: disable=E1101 around various objects created by pandas.

For example, pylint will throw a no member error on the following code:

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":]

Will have the following errors:

E:  6,11: Instance of 'tuple' has no 'ix' member (no-member)
E:  6,11: Instance of 'TextFileReader' has no 'ix' member (no-member)
Michael WS
  • 2,450
  • 4
  • 24
  • 46
  • Would it be correct to assume that you do not wish to globally disable this error check? – shuttle87 Nov 27 '15 at 16:50
  • I don't want to globally disable it. I want to disable it for anything created by pandas. – Michael WS Nov 27 '15 at 16:51
  • The discussion around this answer might convince you that you probably can't, but you can tell pylint to ignore errors on individual lines: http://stackoverflow.com/a/26668602/270001 – Peter Groves Nov 30 '15 at 22:48
  • Would it be helpful to you to have a hierarchy of config files such that the setting is allowed globally by default, but you have more restrictive configs in folders specific to these modules? Ref: http://stackoverflow.com/a/19308989/3182836 – Michelle Welcks Dec 01 '15 at 06:30
  • honestly, it wouldn't. So many modules we use rely on various pandas functionality. – Michael WS Dec 02 '15 at 03:17

3 Answers3

39

You can mark their attributes as dynamically generated using generated-members option.

E.g. for pandas:

generated-members=pandas.*
carabas
  • 506
  • 5
  • 6
  • 5
    Where do you place this line? – caliph Mar 17 '16 at 16:35
  • 1
    @caliph In the .pylintrc - pylint config file. – carabas Mar 19 '16 at 15:19
  • @EdwardHartnett, user3313834: This would only work for members matched by "pandas.*". In the OP, for example, the ix attribute is not accessed on "pandas" but on the object identified as "spy". Something which would work but might be too aggressive, would be to label any member matched precisely by "ix": `generated-members=ix` under the [TYPECHECK] section of your .pylintrc file. – Apteryx Sep 12 '16 at 16:51
  • 3
    This disabled all linting messages for me....until I created a valid .pylintrc file and added `pandas.*` to `generated-members`. Enter `$ pylint --generate-rcfile > .pylintrc` in the terminal (while in your project folder), then open that file, and add `pandas.*` on the `generated-members=` line. – hertopnerd Mar 08 '17 at 16:02
  • 1
    Lot's of people saying this doesn't work for them, but it worked like a charm for me. For those that it is not working for, make sure your `.pylintrc` file is actually being read, and that your regex is correct. Thanks for this answer, saves me so much irritation!! – elethan Apr 14 '17 at 02:47
  • I'm using pylint 2.3.1 with vscode, and it complains that this option is unrecognized. I simply used `# pylint: disable=no-member` at the top of the python module and that fixes the problem; the alternative is marking each relevant line with this and that gets a bit nope from me. – code_dredd Aug 05 '19 at 22:16
11

This failed for me trying to ignore errors in numpy, until I tried

generated-members=np.*

since, like most everybody, I do

import numpy as np

Since generated-members takes a list, one might do:

generated-members=numpy.*,np.*
user10261978
  • 111
  • 1
  • 2
6

Additional information, on top of the answer from carabas:

You will find generated-members in the TYPECHECK section of .pylintrc.
Here is the default one:

[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

Note that the comment about suppressing E0201 is incomplete.
So you have to update this to:

# 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.*
Xavier Lamorlette
  • 1,152
  • 1
  • 12
  • 20