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

TYP: mostly Hashtable and ArrowExtensionArray #56689

Merged
merged 9 commits into from
Jan 2, 2024
18 changes: 10 additions & 8 deletions pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,18 +1311,18 @@ def map(self, mapper, na_action=None):
@overload
def any(
self, *, skipna: Literal[True] = ..., axis: AxisInt | None = ..., **kwargs
) -> bool:
) -> np.bool_:
Copy link
Member Author

Choose a reason for hiding this comment

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

The pandas code expects it to return np.bool_ and not bool (see failing CI on last commit)!

Copy link
Member

@mroeschke mroeschke Jan 2, 2024

Choose a reason for hiding this comment

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

I think it would be better longer term if this returned bool. Would that require a lot of change?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is easy to fix inside all/any but there are at least two places (maybe more) that error after that change:
pandas/core/arrays/masked.py:1164
pandas/core/arrays/masked.py:840

Copy link
Member

Choose a reason for hiding this comment

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

OK this can be a follow up

...

@overload
def any(
self, *, skipna: bool, axis: AxisInt | None = ..., **kwargs
) -> bool | NAType:
) -> np.bool_ | NAType:
...

def any(
self, *, skipna: bool = True, axis: AxisInt | None = 0, **kwargs
) -> bool | NAType:
) -> np.bool_ | NAType:
"""
Return whether any element is truthy.

Expand Down Expand Up @@ -1394,7 +1394,7 @@ def any(
# bool, int, float, complex, str, bytes,
# _NestedSequence[Union[bool, int, float, complex, str, bytes]]]"
np.putmask(values, self._mask, self._falsey_value) # type: ignore[arg-type]
result = values.any().item()
result = values.any()
if skipna:
return result
else:
Expand All @@ -1406,16 +1406,18 @@ def any(
@overload
def all(
self, *, skipna: Literal[True] = ..., axis: AxisInt | None = ..., **kwargs
) -> bool:
) -> np.bool_:
...

@overload
def all(
self, *, skipna: bool, axis: AxisInt | None = ..., **kwargs
) -> bool | NAType:
) -> np.bool_ | NAType:
...

def all(self, *, skipna: bool = True, axis: AxisInt | None = 0, **kwargs):
def all(
self, *, skipna: bool = True, axis: AxisInt | None = 0, **kwargs
) -> np.bool_ | NAType:
"""
Return whether all elements are truthy.

Expand Down Expand Up @@ -1487,7 +1489,7 @@ def all(self, *, skipna: bool = True, axis: AxisInt | None = 0, **kwargs):
# bool, int, float, complex, str, bytes,
# _NestedSequence[Union[bool, int, float, complex, str, bytes]]]"
np.putmask(values, self._mask, self._truthy_value) # type: ignore[arg-type]
result = values.all(axis=axis).item()
result = values.all(axis=axis)

if skipna:
return result
Expand Down
Loading