Skip to content

TYP: NumericDtype._standardize_dtype #47298

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 4 commits into from
Jun 23, 2022
Merged

TYP: NumericDtype._standardize_dtype #47298

merged 4 commits into from
Jun 23, 2022

Conversation

twoertwein
Copy link
Member

No description provided.

@@ -126,7 +127,7 @@ def _standardize_dtype(cls, dtype) -> NumericDtype:
# https://github.com/numpy/numpy/pull/7476
dtype = dtype.lower()

if not issubclass(type(dtype), cls):
if not isinstance(dtype, NumericDtype):
Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is safe to check against NumericDtype and not cls: if it were a more specific sub-class, np.dtype doesn't work with instances of NumericDtype.

Copy link
Member Author

Choose a reason for hiding this comment

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

(mypy and pyright do not support issubclass(type(some_object), some_class) for type narrowing)

@twoertwein twoertwein requested a review from jbrockmendel June 10, 2022 12:41
@twoertwein twoertwein added the Typing type annotations, mypy/pyright type checking label Jun 14, 2022
@mroeschke mroeschke merged commit 76c242d into pandas-dev:main Jun 23, 2022
@mroeschke
Copy link
Member

Thanks @twoertwein

yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
@twoertwein twoertwein deleted the _standardize_dtype branch September 21, 2022 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants