BUG: Incorrect `inspect.signature(pd.DataFrame.rename_axis)` - missing `inplace`

This issue has been tracked since 2022-09-23.

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

import pandas as pd
import inspect
df = pd.DataFrame({'a': [0, 1]})
df.rename_axis('b', inplace=True)
print(df.index.name) # prints 'b', so rename was successful
print('copy' in inspect.signature(df.rename_axis).parameters) # prints True
print('inplace' in inspect.signature(df.rename_axis).parameters) # prints False which is an error

Issue Description

I believe the problem is with the decorator which does not specify inplace in extra arguments (alongside with copy):

pandas/pandas/core/generic.py

Lines 1150 to 1157 in 7d852a9

@rewrite_axis_style_signature("mapper", [("copy", True)])
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "mapper"])
def rename_axis(
self: NDFrameT,
mapper: IndexLabel | lib.NoDefault = lib.no_default,
inplace: bool_t = False,
**kwargs,
) -> NDFrameT | None:

That inplace argument works just fine, as my example above shows.

This issue breaks Modin tests which verify the mutual equality of Modin and pandas API for DataFrames.

Expected Behavior

inspect.signature() should indicate that inplace is a supported argument for pd.DataFrame.rename_axis.

Installed Versions

pd.show_versions()
INSTALLED VERSIONS
------------------
commit           : 87cfe4e38bafe7300a6003a1d18bd80f3f77c763
python           : 3.8.13.final.0
python-bits      : 64
OS               : Windows
OS-release       : 10
Version          : 10.0.22000
machine          : AMD64
processor        : AMD64 Family 25 Model 80 Stepping 0, AuthenticAMD
byteorder        : little
LC_ALL           : None
LANG             : None
LOCALE           : Russian_Russia.1251

pandas           : 1.5.0
numpy            : 1.23.3
pytz             : 2022.2.1
dateutil         : 2.8.2
setuptools       : 65.3.0
pip              : 22.2.2
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
brotli           : None
fastparquet      : None
fsspec           : None
gcsfs            : None
matplotlib       : None
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyreadstat       : None
pyxlsb           : None
s3fs             : None
scipy            : None
snappy           : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
zstandard        : None
tzdata           : None
MarcoGorelli wrote this answer on 2022-09-23

Thanks @vnlitvinov for the report - looks like this is a duplicate of #48692, so closing for now, but please do let me know if you disagree and I should reopen

vnlitvinov wrote this answer on 2022-09-23

I'm not sure if that one is a duplicate, but PR there seems to be fixing the issue I'm seeing based on looking on the code (did not try to run that). Thanks!

MarcoGorelli wrote this answer on 2022-09-23

yeah sorry that's what I meant, the root cause of that one causes what you're seeing here

More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-10-04
Star Count 35430
Watcher Count 1120
Fork Count 15089
Issue Count 3589

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date