TYP: level parameter of DataFrame.groupby has incorrect type hint (should accept sequence) #47548
Closed
3 tasks done
Labels
Bug
Needs Triage
Issue that has not been reviewed by a pandas team member
Typing
type annotations, mypy/pyright type checking
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
The above example runs, demonstrating that the
level
argument toDataFrame.groupby
can usefully take a sequence.This is backed up by the documentation at https://github.com/pandas-dev/pandas/blob/main/pandas/core/shared_docs.py#L106 which states a sequence can be passed in.
But the type annotation on this argument does not accept a sequence:
https://github.com/pandas-dev/pandas/blob/main/pandas/core/groupby/groupby.py#L900
And indeed this causes mypy to complain about the above repro snippet:
Expected Behavior
Type annotation should probably accept a
Sequence[IndexLabel]
too?Installed Versions
INSTALLED VERSIONS
commit : e8093ba
python : 3.9.9.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 85 Stepping 7, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252
pandas : 1.4.3
numpy : 1.22.4
pytz : 2022.1
dateutil : 2.8.2
setuptools : 58.1.0
pip : 21.2.4
Cython : None
pytest : 7.1.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.1.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : 1.0.9
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : 2.1.1
matplotlib : 3.5.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : 1.4.36
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: