Skip to content

BUG: ExcelWriter's engine and supported_extensions are properties #46444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 22, 2022
Merged

BUG: ExcelWriter's engine and supported_extensions are properties #46444

merged 5 commits into from
Mar 22, 2022

Conversation

twoertwein
Copy link
Member

engine and supported_extensions are declared to be properties in ExcelWriter but sub-classes simply assign variables to them. While the differences are subtle, we should either consistently use properties or variables (pyright doesn't like mixing them; mypy doesn't seem to care).

There are more cases where a sub-class does not use a property (found by pyright when enabling reportGeneralTypeIssues):

pandas/core/arrays/datetimes.py:193:20 - error: Expression of type "_scalar_type" cannot be assigned to declared type "property"
pandas/core/arrays/interval.py:200:12 - error: Expression of type "Literal[1]" cannot be assigned to declared type "property"
pandas/core/arrays/period.py:165:20 - error: Expression of type "_scalar_type" cannot be assigned to declared type "property"
pandas/core/arrays/string_.py:94:12 - error: Expression of type "Literal['string']" cannot be assigned to declared type "property"
pandas/core/arrays/string_.py:97:16 - error: Expression of type "NAType" cannot be assigned to declared type "property"
pandas/core/arrays/timedeltas.py:132:20 - error: Expression of type "_scalar_type" cannot be assigned to declared type "property"
pandas/core/dtypes/dtypes.py:176:12 - error: Expression of type "Literal['category']" cannot be assigned to declared type "property"
pandas/core/dtypes/dtypes.py:670:16 - error: Expression of type "NaTType" cannot be assigned to declared type "property"
pandas/core/dtypes/dtypes.py:1045:12 - error: Expression of type "Literal['interval']" cannot be assigned to declared type "property
pandas/core/dtypes/dtypes.py:1394:16 - error: Expression of type "NAType" cannot be assigned to declared type "property"
pandas/core/indexes/numeric.py:372:20 - error: Expression of type "_engine_type" cannot be assigned to declared type "property"
pandas/core/indexes/numeric.py:387:20 - error: Expression of type "_engine_type" cannot be assigned to declared type "property"
pandas/core/indexes/numeric.py:402:20 - error: Expression of type "_engine_type" cannot be assigned to declared type "property"
pandas/core/indexes/range.py:104:20 - error: Expression of type "_engine_type" cannot be assigned to declared type "property"
pandas/core/internals/array_manager.py:706:12 - error: Expression of type "Literal[2]" cannot be assigned to declared type "property
pandas/core/internals/base.py:158:12 - error: Expression of type "Literal[1]" cannot be assigned to declared type "property"
pandas/core/internals/blocks.py:1981:20 - error: Expression of type "Literal[True]" cannot be assigned to declared type "property"
pandas/core/internals/managers.py:1671:23 - error: Expression of type "Literal[True]" cannot be assigned to declared type "property"
pandas/plotting/_matplotlib/core.py:1038:13 - error: Expression of type "Literal['scatter']" cannot be assigned to declared type "property"
pandas/plotting/_matplotlib/core.py:1126:13 - error: Expression of type "Literal['hexbin']" cannot be assigned to declared type "property"
pandas/plotting/_matplotlib/core.py:1156:13 - error: Expression of type "Literal['line']" cannot be assigned to declared type "property"
pandas/plotting/_matplotlib/core.py:1423:13 - error: Expression of type "Literal['bar']" cannot be assigned to declared type "property"
pandas/plotting/_matplotlib/core.py:1606:13 - error: Expression of type "Literal['pie']" cannot be assigned to declared type "property"
pandas/plotting/_matplotlib/hist.py:171:19 - error: Expression of type "Literal['vertical']" cannot be assigned to declared type "property"

@twoertwein
Copy link
Member Author

maybe they should all be variables, as at least engine is asserted to be string and not a property?

assert isinstance(engine_name, str)

@jreback jreback added the IO Excel read_excel, to_excel label Mar 20, 2022
@jreback jreback added this to the 1.5 milestone Mar 20, 2022
@twoertwein
Copy link
Member Author

twoertwein commented Mar 20, 2022

@rhshadrach Based on your recent PR to make book a property, I assume that you would prefer making engine/supported_extensions a property in the sub-classes as well (i.e., changing klass.engine to klass._engine in register_writer to avoid the above assert).

@rhshadrach
Copy link
Member

@twoertwein - Yes, I'd lean toward a property rather than a method here. The most compelling reason to me is that keeps the API from changing.

But this is a really good catch, I didn't realize the subtle inconsistency.

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rhshadrach rhshadrach added the Bug label Mar 22, 2022
@rhshadrach rhshadrach merged commit 75ca237 into pandas-dev:main Mar 22, 2022
@rhshadrach
Copy link
Member

Thanks @twoertwein!

@twoertwein twoertwein deleted the excel branch April 1, 2022 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO Excel read_excel, to_excel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants