-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: fix ignores #40412
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
simonjayhawkins
merged 3 commits into
pandas-dev:master
from
jbrockmendel:typ-dtype-checks
Mar 13, 2021
Merged
TYP: fix ignores #40412
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,8 +191,7 @@ | |
str_t = str | ||
|
||
|
||
# error: Value of type variable "_DTypeScalar" of "dtype" cannot be "object" | ||
_o_dtype = np.dtype(object) # type: ignore[type-var] | ||
_o_dtype = np.dtype("object") | ||
|
||
|
||
_Identity = NewType("_Identity", object) | ||
|
@@ -417,11 +416,7 @@ def __new__( | |
# maybe coerce to a sub-class | ||
arr = data | ||
else: | ||
# error: Argument "dtype" to "asarray_tuplesafe" has incompatible type | ||
# "Type[object]"; expected "Union[str, dtype[Any], None]" | ||
arr = com.asarray_tuplesafe( | ||
data, dtype=object # type: ignore[arg-type] | ||
) | ||
arr = com.asarray_tuplesafe(data, dtype=np.dtype("object")) | ||
|
||
if dtype is None: | ||
arr = _maybe_cast_data_without_dtype(arr) | ||
|
@@ -456,9 +451,7 @@ def __new__( | |
) | ||
# other iterable of some kind | ||
|
||
# error: Argument "dtype" to "asarray_tuplesafe" has incompatible type | ||
# "Type[object]"; expected "Union[str, dtype[Any], None]" | ||
subarr = com.asarray_tuplesafe(data, dtype=object) # type: ignore[arg-type] | ||
subarr = com.asarray_tuplesafe(data, dtype=np.dtype("object")) | ||
return Index(subarr, dtype=dtype, copy=copy, name=name, **kwargs) | ||
|
||
@classmethod | ||
|
@@ -2902,16 +2895,10 @@ def union(self, other, sort=None): | |
# <T> | <T> -> T | ||
# <T> | <U> -> object | ||
if not (is_integer_dtype(self.dtype) and is_integer_dtype(other.dtype)): | ||
# error: Incompatible types in assignment (expression has type | ||
# "str", variable has type "Union[dtype[Any], ExtensionDtype]") | ||
dtype = "float64" # type: ignore[assignment] | ||
dtype = np.dtype("float64") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
else: | ||
# one is int64 other is uint64 | ||
|
||
# error: Incompatible types in assignment (expression has type | ||
# "Type[object]", variable has type "Union[dtype[Any], | ||
# ExtensionDtype]") | ||
dtype = object # type: ignore[assignment] | ||
dtype = np.dtype("object") | ||
|
||
left = self.astype(dtype, copy=False) | ||
right = other.astype(dtype, copy=False) | ||
|
@@ -3906,6 +3893,9 @@ def join( | |
self_is_mi = isinstance(self, ABCMultiIndex) | ||
other_is_mi = isinstance(other, ABCMultiIndex) | ||
|
||
lindexer: Optional[np.ndarray] | ||
rindexer: Optional[np.ndarray] | ||
|
||
# try to figure out the join level | ||
# GH3662 | ||
if level is None and (self_is_mi or other_is_mi): | ||
|
@@ -4003,15 +3993,11 @@ def join( | |
|
||
if return_indexers: | ||
if join_index is self: | ||
# error: Incompatible types in assignment (expression has type "None", | ||
# variable has type "ndarray") | ||
lindexer = None # type: ignore[assignment] | ||
lindexer = None | ||
else: | ||
lindexer = self.get_indexer(join_index) | ||
if join_index is other: | ||
# error: Incompatible types in assignment (expression has type "None", | ||
# variable has type "ndarray") | ||
rindexer = None # type: ignore[assignment] | ||
rindexer = None | ||
else: | ||
rindexer = other.get_indexer(join_index) | ||
return join_index, lindexer, rindexer | ||
|
@@ -4114,15 +4100,11 @@ def _join_non_unique(self, other, how="left", return_indexers=False): | |
left_idx = ensure_platform_int(left_idx) | ||
right_idx = ensure_platform_int(right_idx) | ||
|
||
join_index = np.asarray(lvalues.take(left_idx)) | ||
join_array = np.asarray(lvalues.take(left_idx)) | ||
mask = left_idx == -1 | ||
np.putmask(join_index, mask, rvalues.take(right_idx)) | ||
np.putmask(join_array, mask, rvalues.take(right_idx)) | ||
|
||
# error: Incompatible types in assignment (expression has type "Index", variable | ||
# has type "ndarray") | ||
join_index = self._wrap_joined_index( | ||
join_index, other # type: ignore[assignment] | ||
) | ||
join_index = self._wrap_joined_index(join_array, other) | ||
|
||
if return_indexers: | ||
return join_index, left_idx, right_idx | ||
|
@@ -4286,6 +4268,9 @@ def _join_monotonic(self, other, how="left", return_indexers=False): | |
sv = self._get_engine_target() | ||
ov = other._get_engine_target() | ||
|
||
ridx: Optional[np.ndarray] | ||
lidx: Optional[np.ndarray] | ||
|
||
if self.is_unique and other.is_unique: | ||
# We can perform much better than the general case | ||
if how == "left": | ||
|
@@ -4295,61 +4280,24 @@ def _join_monotonic(self, other, how="left", return_indexers=False): | |
elif how == "right": | ||
join_index = other | ||
lidx = self._left_indexer_unique(ov, sv) | ||
# error: Incompatible types in assignment (expression has type "None", | ||
# variable has type "ndarray") | ||
ridx = None # type: ignore[assignment] | ||
ridx = None | ||
elif how == "inner": | ||
# error: Incompatible types in assignment (expression has type | ||
# "ndarray", variable has type "Index") | ||
join_index, lidx, ridx = self._inner_indexer( # type:ignore[assignment] | ||
sv, ov | ||
) | ||
# error: Argument 1 to "_wrap_joined_index" of "Index" has incompatible | ||
# type "Index"; expected "ndarray" | ||
join_index = self._wrap_joined_index( | ||
join_index, other # type: ignore[arg-type] | ||
) | ||
join_array, lidx, ridx = self._inner_indexer(sv, ov) | ||
join_index = self._wrap_joined_index(join_array, other) | ||
elif how == "outer": | ||
# error: Incompatible types in assignment (expression has type | ||
# "ndarray", variable has type "Index") | ||
join_index, lidx, ridx = self._outer_indexer( # type:ignore[assignment] | ||
sv, ov | ||
) | ||
# error: Argument 1 to "_wrap_joined_index" of "Index" has incompatible | ||
# type "Index"; expected "ndarray" | ||
join_index = self._wrap_joined_index( | ||
join_index, other # type: ignore[arg-type] | ||
) | ||
join_array, lidx, ridx = self._outer_indexer(sv, ov) | ||
join_index = self._wrap_joined_index(join_array, other) | ||
else: | ||
if how == "left": | ||
# error: Incompatible types in assignment (expression has type | ||
# "ndarray", variable has type "Index") | ||
join_index, lidx, ridx = self._left_indexer( # type: ignore[assignment] | ||
sv, ov | ||
) | ||
join_array, lidx, ridx = self._left_indexer(sv, ov) | ||
elif how == "right": | ||
# error: Incompatible types in assignment (expression has type | ||
# "ndarray", variable has type "Index") | ||
join_index, ridx, lidx = self._left_indexer( # type: ignore[assignment] | ||
ov, sv | ||
) | ||
join_array, ridx, lidx = self._left_indexer(ov, sv) | ||
elif how == "inner": | ||
# error: Incompatible types in assignment (expression has type | ||
# "ndarray", variable has type "Index") | ||
join_index, lidx, ridx = self._inner_indexer( # type:ignore[assignment] | ||
sv, ov | ||
) | ||
join_array, lidx, ridx = self._inner_indexer(sv, ov) | ||
elif how == "outer": | ||
# error: Incompatible types in assignment (expression has type | ||
# "ndarray", variable has type "Index") | ||
join_index, lidx, ridx = self._outer_indexer( # type:ignore[assignment] | ||
sv, ov | ||
) | ||
# error: Argument 1 to "_wrap_joined_index" of "Index" has incompatible type | ||
# "Index"; expected "ndarray" | ||
join_index = self._wrap_joined_index( | ||
join_index, other # type: ignore[arg-type] | ||
) | ||
join_array, lidx, ridx = self._outer_indexer(sv, ov) | ||
|
||
join_index = self._wrap_joined_index(join_array, other) | ||
|
||
if return_indexers: | ||
lidx = None if lidx is None else ensure_platform_int(lidx) | ||
|
@@ -6481,12 +6429,8 @@ def _maybe_cast_data_without_dtype(subarr): | |
pass | ||
|
||
elif inferred.startswith("timedelta"): | ||
# error: Incompatible types in assignment (expression has type | ||
# "TimedeltaArray", variable has type "ndarray") | ||
data = TimedeltaArray._from_sequence( # type: ignore[assignment] | ||
subarr, copy=False | ||
) | ||
return data | ||
tda = TimedeltaArray._from_sequence(subarr, copy=False) | ||
return tda | ||
elif inferred == "period": | ||
try: | ||
data = PeriodArray._from_sequence(subarr) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
do not change but I think
dtype
should be the string version to satisfy the typing inasarray_tuplesafe
since not sure if there are perf issues that will accumulate creating a dtype object unnecessarily. but there does look like there may be an issue inasarray_tuplesafe
since"object" in [np.object_, object]
isFalse
so the type annotations forasarray_tuplesafe
maybe incorrect.side note:
I think that we want to import the numpy type definitions for dtype in pandas._typing
in
asarray_tuplesafe
we use NpDtype from pandas._typing, which is not as permissive as the numpy alias, or what is actually accepted by numpy for dtype arguments (with the exception ofobject
which is a false positive but is a special case since it creates issues with static typing)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.
my thought is that these will have to be converted to np.dtype objects somewhere in the call stack, so should be roughly perf neutral. no actual measurements on that though.