Skip to content

Timestamp.replace raises ValueError instead of TypeError when given wrong argument #15240

Closed
@sdementen

Description

@sdementen

Code Sample, a copy-pastable example if possible

from pandas import Timestamp
Timestamp("2012").replace(apple=3)

Problem description

The reimplementation of Timestamp.replace (f8bd08e#diff-05de2950b2c86c9828531957e02d1b87L662) raises a ValueError when a keyword argument does not exist.
Previous implementation used datetime.replace that raises a TypeError when an argument is not valid.
This is a regression and it is probably better to keep API compatibility with the datetime.replace function (modulo extra functionalities).
For autodocumentation/autocomplete purposes, it could also be useful to have explicitly in the function signature the keywords, so instead of::

def replace(self, **kwds):
have::

def replace(self, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, nanosecond=None, tzinfo=None)

Actual Output

Traceback (most recent call last):
File "", line 1, in
File "pandas\tslib.pyx", line 715, in pandas.tslib.Timestamp.replace (pandas\tslib.c:14832)
ValueError: invalid name apple passed

Expected Output

Traceback (most recent call last):
File "", line 1, in
File "pandas\tslib.pyx", line 715, in pandas.tslib.Timestamp.replace (pandas\tslib.c:14832)
TypeError: 'apple' is an invalid keyword argument for this function

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.19.2
nose: None
pip: 9.0.1
setuptools: 27.2.0
Cython: None
numpy: 1.11.3
scipy: None
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: 1.5.2
patsy: None
dateutil: 2.6.0
pytz: 2016.10
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.9.4
boto: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeError ReportingIncorrect or improved errors from pandas

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions