Skip to content

TYP: remove a type: ignore #44288

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

Closed

Conversation

simonjayhawkins
Copy link
Member

No description provided.

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Nov 2, 2021
@jreback jreback added this to the 1.4 milestone Nov 3, 2021
@@ -462,7 +462,7 @@ def find(
dtype_type = type(dtype)
else:
dtype_type = dtype
if issubclass(dtype_type, ExtensionDtype):
if dtype_type in self.dtypes:
Copy link
Contributor

Choose a reason for hiding this comment

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

self.dtypes is actually a list. i am not 100% sure this matters but can you check (e.g. perf)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, calling find with a EA instance or EA type maybe slower if we actually check the registry which I would expect a method called find to do.

but looking some more I think we potentially have another issue.

we call Registry.find from pandas_dtype.

So the immediate thoughts are

  1. pandas.api.types.pandas_dtype is public so any changes need extra scrutiny.
  2. pandas_dtype is annotated and documented as returning a dtype instance whereas Registry.find may return an instance or a Type.
  3. pandas_dtype accepts any object and may pass that onto Registry.find so the annotations for Registry.find may need modification.

will mark as draft for now to prevent merging and try to filter type annotations for functions calling pandas_dtype to lower levels before looking at the perf implications.

>>> import pandas as pd
>>> from pandas.api.types import pandas_dtype
>>> 
>>> pandas_dtype("Int64")
Int64Dtype()
>>> 
>>> pandas_dtype(pd.Int64Dtype)
<class 'pandas.core.arrays.integer.Int64Dtype'>

according to the docs and annotations (point 2), this last statement should return an Int64Dtype instance

I think it maybe better that Registry.find only accepts strings and the other logic for EA types and instances is included in is_extension_array and pandas_dtype. will investigate further.

Copy link
Member

Choose a reason for hiding this comment

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

pandas_dtype is annotated and documented as returning a dtype instance whereas Registry.find may return an instance or a Type.

FWIW i think changing this to always return a dtype instance would fix #31356

@simonjayhawkins simonjayhawkins marked this pull request as draft November 3, 2021 17:38
@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2021

This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Dec 4, 2021
@jreback jreback removed this from the 1.4 milestone Dec 24, 2021
@jreback
Copy link
Contributor

jreback commented Jan 16, 2022

status here?

@jreback jreback modified the milestone: 1.5 Feb 3, 2022
@mroeschke
Copy link
Member

Thanks for the PR, but it appears to have gone stale. Feel free to reopen when you have time to revisit.

@mroeschke mroeschke closed this Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants