0

I am using the Cloud9 IDE and have created a Python project.

However, I keep getting the error in my editor on one line, which is not an error when i run it, which says:

Instance of 'dict' has no 'columns' member

How can I suppress this error, either using Python syntax or Cloud9 syntax?

NOTE: when I run the code, it does not result in an error. My IDE editor simply thinks its an error and warns me.

    xl      = pd.ExcelFile(dataFileUrl)
    sheets  = xl.sheet_names
    data    = xl.parse(sheets[0])


    # the ERROR warning is on the line for data.columns
    for ecol in expectedCols:
        if (ecol in data.columns) == False:
            return {
                'fail':   True,
                'code':   402,
                'msg':    "Incomplete data. Missing: " + ecol
            }

enter image description here

WJA
  • 6,676
  • 16
  • 85
  • 152

3 Answers3

2

This is a known limitation of PyLint as mentioned in their documentation..

E1101

%s %r has no %r member

Function %r has no %r member
Variable %r has no %r member
. . .

Description

Used when an object (variable, function, …) is accessed for a non-existent member.

False positives: This message may report object members that are created dynamically, but exist at the time they are accessed.

Try adding the comment # pylint: disable=no-member at the top of your page (I've never played around with modifying PyLint before, so I'm note entirely sure how this system of configuring via comments works...)

Aaron
  • 10,133
  • 1
  • 24
  • 40
1

You can use try (equivalent to try/catch or rescue/ensure in other languages)

try:
   ecol in data.columns:
except:
    #Handle differently if there is a problem or pass
    return {
            'fail':   True,
            'code':   402,
            'msg':    "Incomplete data. Missing: " + ecol
        }
whodini9
  • 1,434
  • 13
  • 18
  • not working, I am still getting the error message in my IDE. So the issue is not that I get the error when i execute it, I just get a warning sign in my IDE editor. – WJA Mar 20 '17 at 19:48
  • Sounds like a bug in the IDE. `except` without a specific Exception should execute the code. Can you post the relevant code? See http://stackoverflow.com/questions/730764/try-except-in-python-how-do-you-properly-ignore-exceptions – whodini9 Mar 20 '17 at 19:50
  • added it more text text – WJA Mar 20 '17 at 19:52
  • Can you try what I added? – whodini9 Mar 20 '17 at 19:54
  • Yes tried it. Does not work.. still the error. So maybe its the IDE formatter. – WJA Mar 20 '17 at 19:56
  • I changed it one more time. I think this is probably what you are after. You can use `ecol` regularly after the except. If this does not work, then it is almost certainly the IDE – whodini9 Mar 20 '17 at 19:57
  • 1
    This is an anti-pattern and should not be done: https://docs.quantifiedcode.com/python-anti-patterns/correctness/no_exception_type_specified.html#anti-pattern You should better try to understand why your IDE says that... It is probably because something is wrong somewhere if the bug is not documented/reported in the Internet. – LucG Mar 20 '17 at 19:57
  • @LucG looking for the bug for a while now. Cant find anything on it. – WJA Mar 20 '17 at 19:59
1

Following the comment by @LucG, I tried to get the list of column headers in a different way.

Hence following this thread, I used

list(df) 

instead of

df.columns

This suppressed the warning.

Community
  • 1
  • 1
WJA
  • 6,676
  • 16
  • 85
  • 152