Skip to content

AmbiguousTimeError using drop on DatetimeIndex with DST change #18031

Closed
@JrtPec

Description

@JrtPec

Code Sample, a copy-pastable example if possible

import pandas as pd
start = pd.Timestamp('201710290100', tz='Europe/Brussels')
end = pd.Timestamp('201710290300', tz='Europe/Brussels')
index = pd.date_range(start=start, end=end, freq='15min')

index.drop(index[0])

AmbiguousTimeError: Cannot infer dst time from Timestamp('2017-10-29 02:00:00'), try using the 'ambiguous' argument

Problem description

When dropping from a localized DateTimeIndex, behind the scenes the index is converted to UTC, the drop is performed, and then it is converted back to the original timezone. (This is what I make of the traceback).
This second conversion is ambiguous because the original index contains a DST change.

Expected Output

Output of index.drop(index[0])

DatetimeIndex(['2017-10-29 01:15:00+02:00', '2017-10-29 01:30:00+02:00',
'2017-10-29 01:45:00+02:00', '2017-10-29 02:00:00+02:00',
'2017-10-29 02:15:00+02:00', '2017-10-29 02:30:00+02:00',
'2017-10-29 02:45:00+02:00', '2017-10-29 02:00:00+01:00',
'2017-10-29 02:15:00+01:00', '2017-10-29 02:30:00+01:00',
'2017-10-29 02:45:00+01:00', '2017-10-29 03:00:00+01:00'],
dtype='datetime64[ns, Europe/Brussels]', freq='15T')

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeTestingpandas testing functions or related to the test suiteTimezonesTimezone data dtypegood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions