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

error: No overload variant of "DataFrame" matches argument types "Sequence[int]" [call-overload] #384

Closed
randolf-scholz opened this issue Oct 14, 2022 · 7 comments · Fixed by #447

Comments

@randolf-scholz
Copy link
Contributor

import pandas as pd
from collections.abc import Sequence

index: Sequence[int] = [3, 2, 7]
columns = ["a", "b", "c"]
df = pd.DataFrame(index=index, columns=columns)  # ✘ error: [call-overload]
print(df)

If the annotation Sequence[int] is removed, the file parses.

Please complete the following information:

  • Ubuntu 22.04.1
  • Python 3.10.6
  • mypy 0.982
  • pandas 1.5.0
  • pandas-stubs 1.5.0.221012
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Oct 14, 2022

The types for index and columns are Axes, which are defined as:

AnyArrayLike: TypeAlias = Union[Index, Series, np.ndarray]
Axes: TypeAlias = Union[AnyArrayLike, list, dict, range]

We left out Sequence on purpose as an Axes argument, because a plain string is a Sequence. If you change your code to use List[int] instead of Sequence[int], it will work fine.

Because of this unfortunate aspect of python typing, we avoid using Sequence as the type of an argument when we the argument would accept allow a list of strings, but not accept a pure string.

@Dr-Irv Dr-Irv closed this as completed Oct 14, 2022
@randolf-scholz
Copy link
Contributor Author

Seems like this is another case where the absence of a NOT type bites.

Potentially one could discuss allowing at least MutableSequence to catch user types, as strings are immutable.

@bashtage
Copy link
Contributor

Sounds like a good way forward for all of the places where we really want Sequence[Scalar] but can't because of str.

@gandhis1
Copy link
Contributor

That would exclude things that should be included though, tuple, FrozenSet, etc.

@bashtage
Copy link
Contributor

That would exclude things that should be included though, tuple, FrozenSet, etc.

Mostly we are using list[ScalarT] as a work around though, so it seems like it is likely an improvement in many cases. There are also quite a few places where tuple are poorly handled (e.g., anything that indexes).

@randolf-scholz
Copy link
Contributor Author

@gandhis1 using tuple[int, int, int] or tuple[int, ...] in my example currently also raises [call-overload] errors.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Oct 19, 2022

I think that if we add tuple to the definition of Axes in _typing.pyi, we should be OK, as Axes is only used as a type for the argument for the Series and DataFrame constructors, and for reindex().

We just can't support Sequence

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 a pull request may close this issue.

4 participants