Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

pivot_table does not accept Series.name as index, columns or value #1212

Copy link
Copy link
Closed
@cmp0xff

Description

@cmp0xff
Issue body actions

Describe the bug

pivot_table does not accept Series.name as index, columns or value

To Reproduce

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

from collections.abc import Hashable, Sequence

import pandas as pd

ind = pd.Series([0, 0, 1, 1], name="ind")
col = pd.Series([0, 1, 0, 1], name="col")
val = pd.Series([0, 1, 2, 3], name="val")
piv = pd.concat([ind, col, val], axis=1).pivot_table(index=ind.name, columns=col.name, values=val.name)


def foo(data: pd.DataFrame, ind: Hashable | Sequence[Hashable], col: Hashable, val: Hashable) -> pd.DataFrame:
    return data.pivot_table(index=ind , columns=col, values=val)

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

mypy

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

sandbox\pd_series.py:8:60: error: Argument "index" to "pivot_table" of "DataFrame" has incompatible type "Hashable"; expected "str | Grouper | Sequence[Any] | None"  [arg-type]
sandbox\pd_series.py:8:78: error: Argument "columns" to "pivot_table" of "DataFrame" has incompatible type "Hashable"; expected "str | Grouper | Sequence[Any] | None"  [arg-type]
sandbox\pd_series.py:8:95: error: Argument "values" to "pivot_table" of "DataFrame" has incompatible type "Hashable"; expected "str | Sequence[str] | None"  [arg-type]
sandbox\pd_series.py: note: In function "foo":
sandbox\pd_series.py:12:35: error: Argument "index" to "pivot_table" of "DataFrame" has incompatible type "Hashable | Sequence[Hashable]"; expected "str | Grouper | Sequence[Any] | None"  [arg-type]
sandbox\pd_series.py:12:48: error: Argument "columns" to "pivot_table" of "DataFrame" has incompatible type "Hashable"; expected "str | Grouper | Sequence[Any] | None"  [arg-type]
sandbox\pd_series.py:12:60: error: Argument "values" to "pivot_table" of "DataFrame" has incompatible type "Hashable"; expected "str | Sequence[str] | None"  [arg-type]
Found 6 errors 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.13.2

version of type checker

1.15.0

version of installed pandas-stubs

2.2.3.250308

Additional context

Related to pandas-dev/pandas#61432

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.