Skip to content

Series#cumprod overloads #1372

@pinterior

Description

@pinterior

Describe the bug

there are two overload for Series#cumprod:

def cumprod(
self: Series[_str],
axis: AxisIndex = ...,
skipna: _bool = ...,
*args: Any,
**kwargs: Any,
) -> Never: ...
@overload
def cumprod(
self,
axis: AxisIndex = ...,
skipna: _bool = ...,
*args: Any,
**kwargs: Any,
) -> Series[S1]: ...

When the self is Series[Any], according to current typing spec, first one is selected and return type become Never unexpectedly.
(EDIT: I may be misunderstanding Step 5 of the spec. but if the second one is not eliminated at that step, resulting Any is not convenient...)

To Reproduce

from typing import reveal_type
from pandas import Series

def f(s: Series):
    reveal_type(s.cumprod())
$ mypy p.py 
p.py:5: note: Revealed type is "Never"
$ pyright p.py
p.py
  p.py:5:17 - information: Type of "s.cumprod()" is "Never"
0 errors, 0 warnings, 1 information

Please complete the following information:

  • OS: Linux
  • OS Version: Ubuntu 24.04.2
  • Python: 3.12.3
  • mypy 1.18.1
  • pyright: 1.1.405
  • pandas-stubs: 2.3.2.250827

Additional context

originally reported on microsoft/pyright#10935

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions