Skip to content

to_datetime returns TypeError for invalid integer dates with %Y%m%d format #26583

Closed
@nathalier

Description

@nathalier
In [1]: pd.__version__
Out[1]: '0.25.0.dev0+625.g8154efb0c'
pd.to_datetime(20199911, format="%Y%m%d", errors='ignore')
pd.to_datetime(2019121212, format="%Y%m%d", errors='ignore')

throws "TypeError: 'int' object is unsliceable" instead of returning initial values

Traceback (most recent call last):
  File "/home/talka/projects/pandas/tmp.py", line 21, in <module>
    pd.to_datetime(2019121212, format="%Y%m%d", errors='ignore')
  File "/home/talka/projects/pandas/pandas/util/_decorators.py", line 188, in wrapper
    return func(*args, **kwargs)
  File "/home/talka/projects/pandas/pandas/core/tools/datetimes.py", line 626, in to_datetime
    result = convert_listlike(np.array([arg]), box, format)[0]
  File "/home/talka/projects/pandas/pandas/core/tools/datetimes.py", line 270, in _convert_listlike_datetimes
    arg, format, exact=exact, errors=errors)
  File "pandas/_libs/tslibs/strptime.pyx", line 149, in pandas._libs.tslibs.strptime.array_strptime
TypeError: 'int' object is unsliceable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions