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

handle pyright inferring mixed float and int lists #1097

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

Dr-Irv
Copy link
Collaborator

@Dr-Irv Dr-Irv commented Jan 13, 2025

pyright with strict type checking is inferring that a list of mixed int and float is list[int | float], so created overloads for Series.__new__() that makes that a Series[float].

Copy link
Member

@twoertwein twoertwein left a comment

Choose a reason for hiding this comment

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

It would be nice if we could re-write all the overloads more generically, but I assume the union issue (since we use TypeVar with bounds) and the Series sub-classes prevent us from using a more generic approach

    def __new__(
        cls,
        data: Sequence[S1],
        index: Axes | None = ...,
        *,
        dtype: type[S1] = ...,
        name: Hashable = ...,
        copy: bool = ...,
    ) -> Series[S1]: ...

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jan 14, 2025

It would be nice if we could re-write all the overloads more generically, but I assume the union issue (since we use TypeVar with bounds) and the Series sub-classes prevent us from using a more generic approach

Yes, that was exactly the problem. We actually have this overload in there already:

    @overload
    def __new__(
        cls,
        data: S1 | _ListLike[S1] | dict[Hashable, S1] | dict_keys[S1, Any],
        index: Axes | None = ...,
        *,
        dtype: Dtype = ...,
        name: Hashable = ...,
        copy: bool = ...,
    ) -> Self: ...

where _ListLike is defined as:

_ListLike: TypeAlias = (
    ArrayLike | dict[_str, np.ndarray] | Sequence[S1] | IndexOpsMixin[S1]
)

The issue that this PR fixes relates to the union problem of int | float

@twoertwein will you also merge?

@twoertwein twoertwein merged commit 0e22870 into pandas-dev:main Jan 14, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants