-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
CLN: Fixing mypy errors in pandas/conftest.py #29046
Conversation
Can you annotate these instead of ignoring? I think should can just use Dtype from pandas._typing. Might need to modify that to account for built in types
…Sent from my iPhone
On Oct 16, 2019, at 5:30 PM, Angela Ambroz ***@***.***> wrote:
addresses, but does not close, #28926
tests added / passed
passes black pandas
passes git diff upstream/master -u -- "*.py" | flake8 --diff
whatsnew entry
You can view, comment on, or merge this pull request online at:
#29046
Commit Summary
Ignoring some mypy errors related to imports and list inference
File Changes
M pandas/conftest.py (10)
Patch Links:
https://github.com/pandas-dev/pandas/pull/29046.patch
https://github.com/pandas-dev/pandas/pull/29046.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Cool - hadn't seen pandas._typing. Will do. |
Hello @angelaambroz! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-03-25 18:36:23 UTC |
I've left the |
pandas/conftest.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
pandas/conftest.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
You should encapsulate those in Type[...] otherwise this would be looking for an instance of those.
FWIW I’d rather be explicit about these rather than relying on any hierarchy or inference. In the future we’d probably encapsulate in Literal
…Sent from my iPhone
On Oct 18, 2019, at 4:50 PM, Angela Ambroz ***@***.***> wrote:
@angelaambroz commented on this pull request.
In pandas/conftest.py:
> @@ -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
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.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
pandas/_typing.py
Outdated
@@ -18,7 +18,7 @@ | |||
AnyArrayLike = TypeVar("AnyArrayLike", "ExtensionArray", "Index", "Series", np.ndarray) | |||
ArrayLike = TypeVar("ArrayLike", "ExtensionArray", np.ndarray) | |||
DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta") | |||
Dtype = Union[str, np.dtype, "ExtensionDtype"] | |||
Dtype = Type[Union[str, float, bool, np.dtype, "ExtensionDtype"]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dtype = Type[Union[str, float, bool, np.dtype, "ExtensionDtype"]] | |
Dtype = Union[ExtensionDtype, Type[Union[str, float, int, complex, bool]]] |
Somewhat more complicated but the ExtensionDtype
needs to be an instance, so should exclude from the Type
element.
To illustrate:
>>> pd.Series(range(1), dtype=pd.Int64Dtype) # Not what you would expect
0 0
dtype: object
>>> pd.Series(range(1), dtype=pd.Int64Dtype()) # This instance works though
0 0
dtype: object
>>> pd.Series(range(1), dtype=int) # contrast to the builtin, which uses Type[int]
0 0
dtype: int64
cc @TomAugspurger in case there's something I'm missing with the ExtensionDtype
Also @simonjayhawkins do you mind if we include int
in the Union? Understood that it gets replaced as part of the mypy type hierarchy, but given dtype=int
is a valid construct it serves as literal documentation and requires less knowledge of how mypy works. Whenever we get to Python 3.8 as the min version these should be converted to Literal
annotations anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> pd.Series(range(1), dtype=pd.Int64Dtype)
should probably raise. I don't think we can automatically make that work since we have parametrized dtypes. Not sure what that does to the type hint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also @simonjayhawkins do you mind if we include
int
in the Union?
no problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Sorry for the silence on my end. I'm picking this up again now. I didn't follow your comment, @WillAyd (though I committed your suggestion - hence the Outdated
flag). Does this requested review still apply? Thanks.
@angelaambroz thanks for the PR! Are you still working on this? |
Eek, sorry, yes. I'd like to keep working on this. Apologies for the silence. |
pandas/conftest.py
Outdated
@@ -481,14 +483,14 @@ 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: List[Dtype] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will need to change to py3.6 syntax.
pandas/conftest.py
Outdated
STRING_DTYPES = [str, "str", "U"] | ||
FLOAT_DTYPES = [float, "float32", "float64"] # type: List[Dtype] | ||
COMPLEX_DTYPES = [complex, "complex64", "complex128"] # type: List[Dtype] | ||
STRING_DTYPES = [str, "str", "U"] # type: List[Dtype] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
CI fails on
out of the conditional. Halp? 🆘 |
@angelaambroz can you take care of the last comment, so we can finally merge this please? Please ping us once the CI is green, for a faster merge. |
Argh, sorry, I'm traveling and away from a laptop until Jan 8. Can someone
else do the last push? Sorry it's been hanging so long.
…On Sun, Dec 29, 2019, 3:03 PM Marc Garcia ***@***.***> wrote:
@angelaambroz <https://github.com/angelaambroz> can you take care of the
last comment, so we can finally merge this please? Please ping us once the
CI is green, for a faster merge.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#29046?email_source=notifications&email_token=AAWJPII4O7ZCSMV5MV2CMX3Q3CU35A5CNFSM4JBSTLY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHZAFOA#issuecomment-569508536>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAWJPIJPHDLH5ZZRYN4MX7DQ3CU35ANCNFSM4JBSTLYQ>
.
|
You can do the last commit from the website, there is a dropdown to accept the proposed change. I tried to do it myself, but looks like GitHub just let the author accept it. |
Co-Authored-By: William Ayd <william.ayd@icloud.com>
Ack. CI failing linting - it doesn't like the import order in conftest.
|
You can run |
@angelaambroz can you fix up merge conflict? I think this is pretty much ready |
It's failing on type checks now; this was unexpected, but I didn't dive deep into the merge conflicts on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just need to add str
as a valid dtype to resolve CI errors. Something like dtype="boolean"
is valid
pandas/_typing.py
Outdated
@@ -44,7 +45,7 @@ | |||
|
|||
# other | |||
|
|||
Dtype = Union[str, np.dtype, "ExtensionDtype"] | |||
Dtype = Union["ExtensionDtype", Type[Union[str, float, int, complex, bool]]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dtype = Union["ExtensionDtype", Type[Union[str, float, int, complex, bool]]] | |
Dtype = Union["ExtensionDtype", str, Type[Union[str, float, int, complex, bool]]] |
@angelaambroz can you merge master |
Hi @angelaambroz - sorry to chase you up, just wanted to ask whether you're still working on this :) |
@MarcoGorelli Feel free to grab it - I'm being very slow and not finding enough time to get back to this! I'd be happy to continue, but don't want to hold things up. Thanks for checking in! |
It's OK, I don't believe this is too urgent, so feel free to continue and to ask for help if you're stuck |
@angelaambroz any interest in fixing up the merge conflict and addressing last comment? |
👋 Yes, here! I hang my head in shame. But I can do this later today. |
Thanks @angelaambroz for seeing this through |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
whatsnew entry