Skip to content

ENH: add errors=ignore|raise kw to DataFrame.rename #14896

Closed
@rahulporuri

Description

@rahulporuri

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

Activity

jreback

jreback commented on Dec 16, 2016

@jreback
Contributor

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.

added this to the Next Major Release milestone on Dec 16, 2016
changed the title [-]DataFrame.rename doesn't error out when it receives an unknown column name[/-] [+]ENH: add errors=ignore|raise kw to DataFrame.rename[/+] on Dec 16, 2016
TomAugspurger

TomAugspurger commented on Dec 16, 2016

@TomAugspurger
Contributor

Dupe of #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.

modified the milestone: No action on Dec 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignDuplicate ReportDuplicate issue or pull requestEnhancementIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jreback@TomAugspurger@rahulporuri

        Issue actions

          ENH: add errors=ignore|raise kw to DataFrame.rename · Issue #14896 · pandas-dev/pandas