Skip to content

BUG: to_datetime with mixed iso-str and ints #50721

Open
@jbrockmendel

Description

@jbrockmendel
objs = ["2016-01-01 01:02:03+05:00", "2016-01-01 01:02:03+06:00", 0]

pd.to_datetime(objs[::-1])  # <- raises with RuntimeError: No active exception to reraise

pd.to_datetime(objs)  # <- raises ValueError

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/tools/datetimes.py", line 1077, in to_datetime
    result = convert_listlike(argc, format)
  File "pandas/core/tools/datetimes.py", line 449, in _convert_listlike_datetimes
    return _array_strptime_with_fallback(arg, name, utc, format, exact, errors)
  File "pandas/core/tools/datetimes.py", line 480, in _array_strptime_with_fallback
    result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors, utc=utc)
  File "pandas/_libs/tslibs/strptime.pyx", line 513, in pandas._libs.tslibs.strptime.array_strptime
    raise
  File "pandas/_libs/tslibs/strptime.pyx", line 342, in pandas._libs.tslibs.strptime.array_strptime
    raise ValueError(f"time data \"{val}\" doesn't "
ValueError: time data "0" doesn't match format "%Y-%m-%d %H:%M:%S%z", at position 2

cc @MarcoGorelli

Metadata

Metadata

Assignees

Labels

BugConstructorsSeries/DataFrame/Index/pd.array ConstructorsDatetimeDatetime data dtype

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions