Code Sample, a copy-pastable example if possible
import pandas
df = pandas.DataFrame({'a': [1,2], 'b': [3,4]})
df.rename({'C':'D'})
Problem description
I expected the method to throw an error, complaining that the key passed via the dictionary isnt a valid column name in the DataFrame. Instead, nothing happens.
Expected Output
some sort of error.
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Darwin
OS-release: 16.1.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: None.None
pandas: 0.19.0
nose: None
pip: 9.0.1
setuptools: 23.1.0
Cython: None
numpy: 1.10.4
scipy: None
statsmodels: None
xarray: None
IPython: 4.1.2
sphinx: None
patsy: None
dateutil: 2.5.2
pytz: 2016.3
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None
pandas_datareader: None
Comment From: jreback
This is indicated in the doc-string.
Signature: df.rename(index=None, columns=None, **kwargs)
Docstring:
Alter axes input function or functions. Function / dict values must be
unique (1-to-1). Labels not contained in a dict / Series will be left
as-is. Extra labels listed don't throw an error. Alternatively, change
``Series.name`` with a scalar value (Series only).
however, would be willing to add a errors='ignore'|'raise'
argument to control this. So will mark this as an enhancement.
Comment From: TomAugspurger
Dupe of https://github.com/pandas-dev/pandas/issues/13473. I think the decision there was to add a keyword errors={'ignore' | 'raise'}
, with the default being ignore.
@rahulporuri if you're interested in submitting a fix, we'd appreciate it.