Skip to content

ERR: better error message on invalid timestamp parsing #11977

Closed
@jreback

Description

@jreback
In [2]: pd.Timestamp('2010011')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-ccfd37d6ef5d> in <module>()
----> 1 pd.Timestamp('2010011')

/Users/jreback/pandas/pandas/tslib.pyx in pandas.tslib.Timestamp.__new__ (pandas/tslib.c:8958)()
    296         cdef _Timestamp ts_base
    297 
--> 298         ts = convert_to_tsobject(ts_input, tz, unit)
    299 
    300         if ts.value == NPY_NAT:

/Users/jreback/pandas/pandas/tslib.pyx in pandas.tslib.convert_to_tsobject (pandas/tslib.c:24122)()
   1232 
   1233     if util.is_string_object(ts):
-> 1234         return convert_str_to_tsobject(ts, tz, unit)
   1235 
   1236     if ts is None or ts is NaT:

/Users/jreback/pandas/pandas/tslib.pyx in pandas.tslib.convert_str_to_tsobject (pandas/tslib.c:26110)()
   1361                 ts = parse_datetime_string(ts, dayfirst=dayfirst, yearfirst=yearfirst)
   1362             except Exception:
-> 1363                 raise ValueError
   1364 
   1365     return convert_to_tsobject(ts, tz, unit)

ValueError: 

we are should have a nice error message here. This is normally caught for example in to_datetime, but if its only a single Timestamp no message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeError ReportingIncorrect or improved errors from pandas

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions