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
Merged

TYP: mostly Hashtable and ArrowExtensionArray #56689

merged 9 commits into from
Jan 2, 2024

Conversation

twoertwein
Copy link
Member

No description provided.

def any(self, *, skipna: bool, **kwargs) -> bool | NAType:
...

def any(self, *, skipna: bool = True, **kwargs) -> bool | NAType:
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this deviation from the base class on purpose (base class returns always a bool)?

Copy link
Member

Choose a reason for hiding this comment

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

I think so. This can return NA with skipna=False

In [5]: pd.Series([pd.NA], dtype="bool[pyarrow]").any(skipna=False)
Out[5]: <NA>

In [6]: pd.Series([pd.NA], dtype="boolean").any(skipna=False)
Out[6]: <NA>

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay - I will adjust the annotations in the base class to reflect that

@twoertwein twoertwein marked this pull request as ready for review December 31, 2023 02:43
@twoertwein twoertwein requested a review from WillAyd as a code owner December 31, 2023 02:43
@twoertwein twoertwein added 32bit 32-bit systems and removed 32bit 32-bit systems labels Dec 31, 2023
@@ -1541,25 +1541,24 @@ def construct_1d_arraylike_from_scalar(
if isinstance(dtype, ExtensionDtype):
cls = dtype.construct_array_type()
seq = [] if length == 0 else [value]
subarr = cls._from_sequence(seq, dtype=dtype).repeat(length)
return cls._from_sequence(seq, dtype=dtype).repeat(length)
Copy link
Member Author

Choose a reason for hiding this comment

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

Avoids a mypy error (assigning a new type to subarr).

@@ -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

Copy link
Contributor

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

All looks good to me - will let others review/approve/merge

@mroeschke mroeschke added the Typing type annotations, mypy/pyright type checking label Jan 2, 2024
@mroeschke mroeschke added this to the 3.0 milestone Jan 2, 2024
@mroeschke mroeschke merged commit 486b440 into pandas-dev:main Jan 2, 2024
39 checks passed
@mroeschke
Copy link
Member

Thanks @twoertwein

@twoertwein twoertwein deleted the types2 branch January 17, 2024 02:49
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