Skip to content
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

#25942 Added ArrayLike and Dtype to pandas._typing #25943

Merged
merged 5 commits into from
Apr 10, 2019

Conversation

gwrome
Copy link
Contributor

@gwrome gwrome commented Mar 31, 2019

pandas/_typing.py Outdated Show resolved Hide resolved
@WillAyd WillAyd added the Typing type annotations, mypy/pyright type checking label Mar 31, 2019
@codecov
Copy link

codecov bot commented Mar 31, 2019

Codecov Report

Merging #25943 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #25943      +/-   ##
==========================================
- Coverage   91.81%   91.81%   -0.01%     
==========================================
  Files         175      175              
  Lines       52580    52587       +7     
==========================================
+ Hits        48278    48281       +3     
- Misses       4302     4306       +4
Flag Coverage Δ
#multiple 90.37% <100%> (ø) ⬆️
#single 41.9% <100%> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/core/arrays/base.py 98.34% <100%> (ø) ⬆️
pandas/core/arrays/sparse.py 92.19% <100%> (ø) ⬆️
pandas/_typing.py 100% <100%> (ø) ⬆️
pandas/io/gbq.py 75% <0%> (-12.5%) ⬇️
pandas/core/frame.py 96.79% <0%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de3a85c...0761dab. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 31, 2019

Codecov Report

Merging #25943 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #25943      +/-   ##
==========================================
+ Coverage   91.81%   91.83%   +0.01%     
==========================================
  Files         175      175              
  Lines       52580    52524      -56     
==========================================
- Hits        48278    48236      -42     
+ Misses       4302     4288      -14
Flag Coverage Δ
#multiple 90.39% <100%> (+0.02%) ⬆️
#single 40.72% <100%> (-1.25%) ⬇️
Impacted Files Coverage Δ
pandas/core/arrays/base.py 98.34% <100%> (ø) ⬆️
pandas/core/arrays/sparse.py 92.2% <100%> (+0.01%) ⬆️
pandas/_typing.py 100% <100%> (ø) ⬆️
pandas/io/clipboard/__init__.py 39.21% <0%> (-17.65%) ⬇️
pandas/io/gbq.py 75% <0%> (-12.5%) ⬇️
pandas/io/clipboard/clipboards.py 18.51% <0%> (-12.35%) ⬇️
pandas/util/_decorators.py 91.34% <0%> (-0.17%) ⬇️
pandas/core/frame.py 96.79% <0%> (-0.12%) ⬇️
pandas/io/common.py 91.83% <0%> (-0.05%) ⬇️
pandas/core/ops.py 91.72% <0%> (-0.02%) ⬇️
... and 36 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de3a85c...674c52f. Read the comment docs.

@jreback jreback added this to the 0.25.0 milestone Apr 1, 2019
pandas/_typing.py Outdated Show resolved Hide resolved
pandas/_typing.py Outdated Show resolved Hide resolved
@WillAyd
Copy link
Member

WillAyd commented Apr 2, 2019 via email

@@ -30,6 +30,7 @@
ABCIndexClass, ABCSeries, ABCSparseArray, ABCSparseSeries)
from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna

from pandas._typing import SparseDtype
Copy link
Contributor

Choose a reason for hiding this comment

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

this is too magical as this name gets shadowed immediately.

from pandas.core.dtypes.generic import ABCExtensionArray

ArrayLike = Union[ABCExtensionArray, np.ndarray]
SparseDtype = Union[str, np.dtype, ExtensionDtype,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think maybe we should call this something else, as SparseDtype is an actual type that we have (see my comment below)

cc @TomAugspurger

alternatively, maybe we just move this particular type definition into pandas/core/arrays.py and don't put it here (as I am not sure we are going to be using this particular type very often).

Copy link
Contributor Author

@gwrome gwrome Apr 3, 2019

Choose a reason for hiding this comment

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

I think I misunderstood the comment above, then:

I think we need to use SparseDtype here explicity here

Did you mean inside the Union as part of the definition itself?

Copy link
Member

Choose a reason for hiding this comment

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

Might have missed the conversation but we just want to define Dtype here no?

Agreed SparseDtype in particular will have pretty limited usage, so not something I think we need to expose in this module

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah i think we can make this only Dtype (so remove the Type references )

these are generic types so we want to use in many places (eg in pandas.core.dtypes.dtypes)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just so I'm on the right page after all the discussion above, does rolling back to the first commit get us where we need to be?

That would return _typing.py to defining Dtype as is it currently defined in the existing type annotation, remove the specific Type references that were added after discussion above (Type[float], Type[int], Type[object]), and replace them with plain (and potentially over-broad) Type:

Dtype = Union[str, np.dtype, ExtensionDtype, Type]

Alternatively, do we want to go back to Dtype and drop all the Types? (This is how I interpret @jreback's "so remove the Type references" comment immediately above.) That would leave

Dtype = Union[str, np.dtype, ExtensionDtype]

I don't think this change would comply with the documented functionality of SparseDtype's init method that we pulled the definition from, but it does satisfy mypy.

Copy link
Member

Choose a reason for hiding this comment

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

The former should work here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that work for you, @jreback?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes @gwrome I think Dtype = Union[str, np.dtype, ExtensionDtype] looks reasonable assuming it works

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@WillAyd for Dtype = Union[str, np.dtype, ExtensionDtype, Type]
@jreback for Dtype = Union[str, np.dtype, ExtensionDtype]

Both satisfy mypy. I propose we pick the more restrictive one: Dtype = Union[str, np.dtype, ExtensionDtype].

Copy link
Member

Choose a reason for hiding this comment

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

The only reason I was thinking we might need Type is because something like dtype=float is valid. OK to start smaller for now though - can add in later when it comes up

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm @jreback

@jreback jreback merged commit 6d9b702 into pandas-dev:master Apr 10, 2019
@jreback
Copy link
Contributor

jreback commented Apr 10, 2019

thanks @gwrome

@gwrome gwrome deleted the typing-arraylike-dtype branch April 10, 2019 13:26
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.

Add ArrayLike an Dtype definitions to pandas._typing
3 participants