pylint icon indicating copy to clipboard operation
pylint copied to clipboard

False positive ``abstract-class-instantiated`` with ``pandas.ExcelWriter``

Open mhooreman opened this issue 6 years ago • 22 comments

Hello,

Steps to reproduce

Run pylint on the following code:

"""Lorem ipsum"""

import pandas as pd


def demo():
    """Demo for the false positive"""
    with pd.ExcelWriter("demo.xlsx") as writer:
        print(writer)

Current behavior

Pylint gives: abstract-class-instantiated(E0110): test.py:8:9: demo: Abstract class 'ExcelWriter' with abstract methods instantiated

Expected behavior

No issue

pylint --version output

  • Astroid 2.2.5
  • Pylint 2.3.1
  • Python 3.7.4
  • GCC 7.4.0

Discussion

This ticket has originally been opened on pandas github: https://github.com/pandas-dev/pandas/issues/27634

According to the discussions there, it seems that pylint has issues with introspection of objects defining __new__

mhooreman avatar Aug 13 '19 14:08 mhooreman

I just ran into this exact issue.

dasrequiem avatar Aug 14 '19 18:08 dasrequiem

Thanks for the report folks!

PCManticore avatar Aug 16 '19 15:08 PCManticore

You're welcome. Thanks for your help.

Le ven. 16 août 2019 17:22, Claudiu Popa [email protected] a écrit :

Thanks for the report folks!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/PyCQA/pylint/issues/3060?email_source=notifications&email_token=ABYIHFTFNBN6FLJGJPQ6LQTQE3A4DA5CNFSM4ILLMDY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4O5E4Y#issuecomment-522048115, or mute the thread https://github.com/notifications/unsubscribe-auth/ABYIHFXN7REEB5LVEZYNEFDQE3A4DANCNFSM4ILLMDYQ .

mhooreman avatar Aug 16 '19 15:08 mhooreman

To save y'all 10s here is the comment line to temporarily disable this error and point to this page: # https://github.com/PyCQA/pylint/issues/3060 pylint: disable=abstract-class-instantiated

lleeoo avatar Aug 26 '19 04:08 lleeoo

+1

gk2go avatar Nov 09 '19 12:11 gk2go

Guys, this is driving me mad, could someone please tell me how to implement a temporary fix.

drddavi avatar Nov 19 '19 22:11 drddavi

@UrAvgDeveloper this is what I did to disable this check globally, you need a .pylintrc file, look for [MESSAGES CONTROL] then for disable= and add abstract-class-instantiated image

EdgarOrtegaRamirez avatar Nov 19 '19 22:11 EdgarOrtegaRamirez

I encountered the same issue.

I get a pylint message on the line: writer = pd.ExcelWriter(output, engine='xlsxwriter')

'Abstract class ExcelWriter with abstract methods instantiated'

pandas==0.25.3

usser123 avatar Feb 17 '20 20:02 usser123

same issue as of today writer = pd.ExcelWriter('path to file') 'Abstract class 'ExcelWriter' with abstract methods instantiated'

liamsuma avatar Feb 25 '20 17:02 liamsuma

Same here. Used the following syntax as a temporary fix: with pd.ExcelWriter(outfile_name) as xl_writer: #pylint: disable=abstract-class-instantiated

grishagin avatar Feb 26 '20 14:02 grishagin

Same as of today: (abstract-class-instantiated)Abstract class 'ExcelWriter' with abstract methods instantiated

Svestis avatar Mar 06 '20 10:03 Svestis

+1 Abstract class 'ExcelWriter' with abstract methods instantiatedpylint(abstract-class-instantiated)

acamposc avatar Mar 09 '20 14:03 acamposc

For me as well: Abstract class 'ExcelWriter' with abstract methods instantiated

MattSom avatar Mar 30 '20 16:03 MattSom

Me too :(

ffanderson avatar Apr 30 '20 15:04 ffanderson

with pd.ExcelWriter(outfile_name) as xl_writer: #pylint: disable=abstract-class-instantiated

Doesn't this just thrown a line length error?

ffanderson avatar Apr 30 '20 15:04 ffanderson

with pd.ExcelWriter(outfile_name) as xl_writer: #pylint: disable=abstract-class-instantiated

Doesn't this just thrown a line length error?

Not in my case... I didn't change any of the pylint's defaults.
In any case, one can adjust that setting: https://stackoverflow.com/questions/52058886/visual-studio-code-with-pylint-and-autopep8-how-can-i-avoid-pylint-to-complain

grishagin avatar Apr 30 '20 15:04 grishagin

I am still getting this on v2.12.2; not sure why! Same code, pandas.ExcelWriter

aaronsmith1234 avatar Feb 25 '22 16:02 aaronsmith1234

@DanielNoord I started to look at this issue and I'm not totally convinced this is an astroid issue. The same thing can be reproduced with:

import abc


class Test(metaclass=abc.ABCMeta):
    def __new__(cls):
        pass

    @property
    @abc.abstractmethod
    def sheets(self):
        """Mapping of sheet names to sheet objects."""

    @property
    @abc.abstractmethod
    def book(self):
        """
        Book instance. Class type will depend on the engine used.
        This attribute can be used to access engine-specific features.
        """


test = Test()

and also without __new__ in the definition. In fact, the functional tests hint that raising this message is expected.

So is there something specific for pandas that needs to be done in astroid, or can we do something in pylint's _check_inferred_class_is_abstract to nope out if a __new__ method is defined? Just throwing ideas....

clavedeluna avatar Dec 28 '22 15:12 clavedeluna

Good find, although the check can't be that simple sadly. Consider:

import abc


class Test(metaclass=abc.ABCMeta):
    def __new__(cls):
        print("Test.__new__")
        return super().__new__(cls)

    @property
    @abc.abstractmethod
    def sheets(self):
        """Mapping of sheet names to sheet objects."""

    @property
    @abc.abstractmethod
    def book(self):
        """
        Book instance. Class type will depend on the engine used.
        This attribute can be used to access engine-specific features.
        """


test = Test()

Anyway, this is indeed something that should be fixed in pylint.

DanielNoord avatar Dec 29 '22 21:12 DanielNoord

So is the idea to fix this issue to not raise abstract-class-instantiated in the case the class has an implemented __new__ method?

clavedeluna avatar Dec 30 '22 12:12 clavedeluna

No, we should not raise it if there wouldn't be an exception raised. In the example I gave the code would still crash, so the message is valid.,

DanielNoord avatar Dec 30 '22 14:12 DanielNoord

Hi Any update on this? I still have the issue with pd 2.0.2 Thanks

mhooreman avatar Jun 29 '23 11:06 mhooreman