Describe the bug
If you grab the name of an Index as Index.name, you should be able to use that value in rename_axis
To Reproduce
import pandas as pd
def indexchg(df: pd.DataFrame) -> pd.DataFrame:
idx_name = df.index.name
result = df.set_index("foo")
result = result.reset_index().rename_axis(idx_name)
return result
error from pyright
indexasym.py
c:\Code\pandas-stubs\play\indexasym.py:6:38 - error: Argument of type "Hashable | None" cannot be assigned to parameter "mapper" of type "Scalar | ListLike | None" in function "rename_axis"
Type "Hashable | None" is not assignable to type "Scalar | ListLike | None"
Type "Hashable" is not assignable to type "Scalar | ListLike | None"
"Hashable" is not assignable to "str"
"Hashable" is not assignable to "bytes"
"Hashable" is not assignable to "date"
"Hashable" is not assignable to "datetime"
"Hashable" is not assignable to "timedelta"
"Hashable" is not assignable to "datetime64[Any]"
... (reportArgumentType)
System specifications
- OS and its version: Windows 11
- python version: 3.12
- type checker and its version: pyright 1.1.411
- version of installed
pandas-stubs: version on main commit 2b7f9f41f103cfec140888f4dae19724c83ea580
Additional context
I'm not sure if the right way to handle this is to make Index.name return Scalar | None or to modify rename_axis() to accept Hashable . Open to either.
Describe the bug
If you grab the name of an
IndexasIndex.name, you should be able to use that value inrename_axisTo Reproduce
error from pyright
System specifications
pandas-stubs: version onmaincommit2b7f9f41f103cfec140888f4dae19724c83ea580Additional context
I'm not sure if the right way to handle this is to make
Index.namereturnScalar | Noneor to modifyrename_axis()to acceptHashable. Open to either.