Skip to content

Wrong typing for the values argument of the pandas.DataFrame.pivot_table method #885

Closed
@airatk

Description

@airatk

Describe the bug
The values argument of the pandas.DataFrame.pivot_table method has type of str | None:

def pivot_table(
self,
values: _str | None = ...,
index: _str | Grouper | Sequence | None = ...,
columns: _str | Grouper | Sequence | None = ...,
aggfunc=...,
fill_value: Scalar | None = ...,
margins: _bool = ...,
dropna: _bool = ...,
margins_name: _str = ...,
observed: _bool = ...,
) -> DataFrame: ...

But the Pandas documentation says that values may have not only a string value, but also a list-like value:
Docs of pandas.DataFrame.pivot_table

To Reproduce

  1. A minimal runnable pandas example that is not properly checked by the stubs:
from pandas import DataFrame

data_frame = DataFrame({
    'a': [1, 2],
    'b': [1, 2],
    'c': [1, 2],
    'd': [1, 2],
})
data_frame.pivot_table(
    values=['a', 'b'],
    index=['c', 'd'],
)
  1. I am using mypy.
  2. The error message received from mypy:
error: Argument "values" to "pivot_table" of "DataFrame" has incompatible type "list[str]"; expected "str | None"  [arg-type]
Found 1 error in 1 file (checked 80 source files)

Please complete the following information:

  • OS: Ubuntu
  • OS version: 23.10
  • python version: 3.10.11
  • mypy version: 1.8.0
  • pandas-stubs version: 2.2.0.240218

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions