Skip to content

CLN: Fixing mypy errors in pandas/conftest.py #29046

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 16 commits into from
Mar 25, 2020
5 changes: 3 additions & 2 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
from hypothesis import strategies as st
import numpy as np
import pytest
from pytz import FixedOffset, utc
from pytz import FixedOffset, utc # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

This is the same as #28932 - I think this needs to be fixed upstream in Typeshed. Would you be interested in submitting that there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure - I can give it a shot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Picking this up again - just got the changes merged in typeshed (python/typeshed#3393). I see that there are now some conflicts with master; I can address those and pick this up again in the next couple days.

Copy link
Member

Choose a reason for hiding this comment

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

Great job and thanks for fixing that upstream! Still not a rush on our end but should make it into the next mypy release. Will be helpful for us in a few places


import pandas.util._test_decorators as td
from pandas._typing import Dtype

import pandas as pd
from pandas import DataFrame
Expand Down Expand Up @@ -481,7 +482,7 @@ def tz_aware_fixture(request):

UNSIGNED_INT_DTYPES = ["uint8", "uint16", "uint32", "uint64"]
UNSIGNED_EA_INT_DTYPES = ["UInt8", "UInt16", "UInt32", "UInt64"]
SIGNED_INT_DTYPES = [int, "int8", "int16", "int32", "int64"]
SIGNED_INT_DTYPES = [int, "int8", "int16", "int32", "int64"] # type: Dtype
Copy link
Member

Choose a reason for hiding this comment

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

This is actually a List[Dtype]

Copy link
Member

@WillAyd WillAyd Oct 17, 2019

Choose a reason for hiding this comment

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

I think Dtype needs to be updated in pandas._typing to include Type[Union[float, int, str, bool]] for when the built-in values get provided - could you make that change as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, sure - thanks for the guidance.

Copy link
Member

Choose a reason for hiding this comment

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

Type[Union[float, str, bool]] would be sufficient as int is duck type compatible with float see https://mypy.readthedocs.io/en/latest/duck_type_compatibility.html#duck-type-compatibility

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, both. Just pushed what I think you both meant - let me know. I'm still learning about types! Looks like complex was also duck typed to float.

SIGNED_EA_INT_DTYPES = ["Int8", "Int16", "Int32", "Int64"]
ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES
ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES
Expand Down