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

No type hint for Series containing lists of strings in Series.str.split method with expand=False #1074

Closed
pan-vlados opened this issue Dec 18, 2024 · 0 comments · Fixed by #1075

Comments

@pan-vlados
Copy link
Contributor

Describe the bug

The stubs for pandas_stubs.core.strings.StringMethods.split do not return pandas.Series[list[str]] type with expand=False parameter for Series/Index containing lists of strings as described in docs.

To Reproduce

Use VS Code with Pylance extension:

  1. The following:
    from pandas import Series
    s = Series(["one", "two"])
    def split(s: "Series[str]") -> "Series[list[str]]":  # error
        return s.str.split(expand=False)
    split(s)
    cause Pylance error below:
    Type "list[str]" cannot be assigned to type variable "S1@Series"
    Type "list[str]" is not assignable to upper bound "Dtype | bytes | date | time | bool | int | float | complex | datetime | timedelta | Period | Interval[Unknown] | CategoricalDtype | BaseOffset" for type variable "S1@Series"
        Type "list[str]" is not assignable to type "Dtype | bytes | date | time | bool | int | float | complex | datetime | timedelta | Period | Interval[Unknown] | CategoricalDtype | BaseOffset"
        "list[str]" is not assignable to "str"
        "list[str]" is not assignable to "bytes"
        "list[str]" is not assignable to "date"
        "list[str]" is not assignable to "time"
        "list[str]" is not assignable to "bool"
        "list[str]" is not assignable to "int"
    ...PylancereportInvalidTypeArguments
    
  2. The following is type of "Series[Unknown]":
    from pandas import Series
    s = Series(["one", "two"])
    s = s.str.split(expand=False)
    reveal_type(s)  # Type of "s" is "Series[Unknown]"

Please complete the following information:

  • OS : MacOS
  • OS Version : Sonoma 14.7.1
  • python : 3.10.14
  • processor : arm64
  • VS Code : 1.96.0 (Universal)
  • pandas : 2.2.3
  • pandas-stubs : 2.2.3.241126
  • Pylance : 2024.12.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant