16

pylint complain about pandas class instances::

I have db instance that has data (a panda Dataframe) as instance.

If I call e.g. iloc or shape on it::

cols = db.data.shape
xxx = db.data.iloc[1:4, 0:9]

pylint complain about::

E: 36,18: Instance of 'TextFileReader' has no 'iloc' member (no-member)
E: 92,30: Instance of 'TextFileReader' has no 'shape' member (no-member)
E: 92,30: Instance of 'tuple' has no 'shape' member (no-member)

I've try How do I get PyLint to recognize numpy members? and Disabling Pylint no member- E1101 error for specific libraries with no success.

Community
  • 1
  • 1
user3313834
  • 7,327
  • 12
  • 56
  • 99
  • It seems db.data is a TextFileReader instance instead of DataFrame. This happens under some condition like https://stackoverflow.com/questions/41844485/why-the-object-which-i-read-a-csv-file-using-pandas-from-is-textfilereader-obj, have you checked it? – YCFlame Apr 09 '18 at 10:42
  • As @YCFlame pointed out, pylint thinks the type is TextFileReader. One can only guess as to why, without incuding your code of what db. – de1 Oct 08 '18 at 11:49
  • This looks like a possible solution to getting TextFileReader to DataFrame https://stackoverflow.com/a/70212439/761829 – Jed Mitten Feb 07 '22 at 18:25
  • I does not look reasonable to change the code jute to workaround pylint Pbs, did you ? – user3313834 Feb 12 '22 at 15:48
  • Maybe you should just suppress errors with adding comment `# pylint: disable=no-member` – Andrew Berezin Mar 16 '22 at 07:11

1 Answers1

2

This seems to be an open issue in pylint that has been marked high priority as of March 14th 2022.

The issue stems from the underlying AST engine that pylint uses that has a limit to the number of inferences it can make at runtime as a bid to improve performance.

For posteriority in case the link above ever dies, the workaround is as follows:

pylint some_file_to_lint.py --init-hook "import astroid; astroid.context.InferenceContext.max_inferred = 500"

Or in .pylintrc:

[MASTER]

init-hook = "import astroid; astroid.context.InferenceContext.max_inferred = 500"
Rayan Hatout
  • 640
  • 5
  • 22