Skip to content

TYP: misc return types #57430

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 1 commit into from
Feb 16, 2024
Merged

TYP: misc return types #57430

merged 1 commit into from
Feb 16, 2024

Conversation

twoertwein
Copy link
Member

No description provided.

@@ -11815,19 +11899,19 @@ def kurt(
product = prod

@doc(make_doc("cummin", ndim=2))
def cummin(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs):
def cummin(self, axis: Axis = 0, skipna: bool = True, *args, **kwargs) -> Self:
Copy link
Member Author

Choose a reason for hiding this comment

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

None is not documented and 0 seems to behave the same?!

@property
def _constructor(self) -> Callable[..., Self]:
def _constructor(self) -> Callable[..., Self]: # type: ignore[override]
Copy link
Member Author

Choose a reason for hiding this comment

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

Should technically be type[Self] but the NDFrame constructor allows far fewer arguments than the Series/DataFrame constructor, which leads to many errors when _constructor()(...) is called inside NDFrame, which are at runtime only reached by sub-classes.

@twoertwein twoertwein marked this pull request as ready for review February 15, 2024 03:54
@twoertwein twoertwein requested a review from Dr-Irv as a code owner February 15, 2024 03:54
@@ -118,6 +118,7 @@
Concatenate: Any = None

HashableT = TypeVar("HashableT", bound=Hashable)
HashableT2 = TypeVar("HashableT2", bound=Hashable)
Copy link
Member

Choose a reason for hiding this comment

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

Curious why we need a second one?

Copy link
Member Author

Choose a reason for hiding this comment

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

needed for _from_nested_dict. When using the same TypeVar in a function signature, the type checkers bind these to the same type:

def (x: HashableT) -> HashableT: ...

x(None) # return None
x((1, 2, 3)) # return tuple[int, int, int]

When we have a function that tries to bind two different sets of types, we need a new TypeVar

def (x: HashableT, y: HashableT2) -> dict[HashableT, dict[HashableT2, Any]]: ...

(pandas-stubs uses the name HashableT2)

@mroeschke mroeschke added the Typing type annotations, mypy/pyright type checking label Feb 15, 2024
@mroeschke mroeschke added this to the 3.0 milestone Feb 16, 2024
@mroeschke mroeschke merged commit 8611eca into pandas-dev:main Feb 16, 2024
@mroeschke
Copy link
Member

Thanks @twoertwein

@twoertwein twoertwein deleted the typing branch April 7, 2024 10:59
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
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