Skip to content

Rich comparison methods, e.g. Series.eq, do not like non-SeriesDType objects #1288

@cmp0xff

Description

@cmp0xff

Describe the bug

For example, when Thing is an Enum, series.eq(Thing.MEMBER) gives an error from mypy.

To Reproduce

Provide a minimal runnable pandas example that is not properly checked by the stubs.

from enum import Enum, auto

import pandas as pd


class Thing(Enum):
    ONE = auto()
    TWO = auto()


series = pd.Series([Thing.ONE])
series.eq(Thing.ONE)  # error: Argument 1 to "eq" of "Series" has incompatible type "Thing"; expected "str | bytes | date | datetime | timedelta | <12 more items>"  [arg-type]

Indicate which type checker you are using (mypy or pyright).

mypy

Show the error message received from that type checker while checking your example.

compare_enums.py:13: error: Argument 1 to "eq" of "Series" has incompatible type "Thing"; expected "str | bytes | date | datetime | timedelta | <12 more items>"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Please complete the following information:

OS: [e.g. Windows, Linux, MacOS]

Windows

OS Version [e.g. 22]

10

python version

3.12.10

version of type checker

1.17.0

version of installed pandas-stubs

2.3.0.250703

Additional context

None

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