Skip to content

TYP: fix ignores #40389

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 10 commits into from
Mar 12, 2021
Merged

TYP: fix ignores #40389

merged 10 commits into from
Mar 12, 2021

Conversation

jbrockmendel
Copy link
Member

i get a bunch of noise in my local mypy output, so will have to see what the CI says

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

Thanks @jbrockmendel will push a merge master since there are still mypy errors here to resolve.

vals = vals.to_numpy( # type: ignore[attr-defined]
dtype=float, na_value=np.nan
)
if isinstance(vals, ExtensionArray):
Copy link
Member

Choose a reason for hiding this comment

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

the function signature has vals: np.ndarray. also needs updating

@@ -2271,28 +2271,18 @@ def pre_processor(vals: np.ndarray) -> Tuple[np.ndarray, Optional[Type]]:
"'quantile' cannot be performed against 'object' dtypes!"
)

inference = None
inference: Optional[np.dtype] = None
Copy link
Member

Choose a reason for hiding this comment

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

the return type is Tuple[np.ndarray, Optional[Type]] in the function signature. so that can also now be narrowed.

Copy link
Member

Choose a reason for hiding this comment

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

was needed anyway for mypy fixup

@@ -166,7 +170,7 @@ def _make_selectors(self):

comp_index = ensure_platform_int(comp_index)
stride = self.index.levshape[self.level] + self.lift
self.full_shape = ngroups, stride
self.full_shape = ngroups, int(stride) # int() for mypy
Copy link
Member

Choose a reason for hiding this comment

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

we probably don't want to be casting numpy integer types to python ints just to appease mypy. We probably need an int-like alias to use where we currently use int in type annotations.

I think better to leave this unchanged until we've had that discussion.

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds good, will revert

def _reorder_for_extension_array_stack(arr, n_rows: int, n_columns: int):
def _reorder_for_extension_array_stack(
arr: ExtensionArray, n_rows: int, n_columns: int
) -> ExtensionArray:
Copy link
Member

Choose a reason for hiding this comment

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

probably should be a typevar. but also ok to leave as is for now if not needed as this is internal

@@ -52,7 +51,7 @@ def get_indexer_indexer(
na_position: str,
sort_remaining: bool,
key: IndexKeyFunc,
) -> Optional[np.array]: # type: ignore[valid-type]
) -> Optional[np.ndarray]:
Copy link
Member

Choose a reason for hiding this comment

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

you found the bonus low hanger! 😄

@@ -534,25 +534,19 @@ def _to_datetime_with_unit(arg, unit, name, tz, errors: Optional[str]) -> Index:
# GH#30050 pass an ndarray to tslib.array_with_unit_to_datetime
# because it expects an ndarray argument
if isinstance(arg, IntegerArray):
result = arg.astype(f"datetime64[{unit}]")
res = arg.astype(f"datetime64[{unit}]")
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: res-> arr (I think once the type is added for arg in the signature, we will get an Incompatible types in assignment in arg = getattr(arg, "_values", arg) anyway.

# error: Incompatible types in assignment (expression has type "TimedeltaIndex",
# variable has type "ndarray")
value = TimedeltaIndex(value, unit="ns", name=name) # type: ignore[assignment]
value = TimedeltaIndex(td64arr, unit="ns", name=name)
Copy link
Member

Choose a reason for hiding this comment

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

could also return TimedeltaIndex ... without the intermediate assignment, but the td64arr naming is also an improvement anyway.

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Mar 12, 2021
@simonjayhawkins simonjayhawkins added this to the 1.3 milestone Mar 12, 2021
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

Thanks @jbrockmendel for the updates. lgtm pending green

@WillAyd WillAyd merged commit 4007513 into pandas-dev:master Mar 12, 2021
@jbrockmendel jbrockmendel deleted the typ-ignore-less branch March 12, 2021 22:42
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
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.

3 participants