Skip to content

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

)

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

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

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! 😄

# 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