Skip to content

Indexing/Slicing tz-aware TimeSeries fails when using datetime #2575

Closed
@timtroendle

Description

@timtroendle

The following code should clarify the problem:

import pandas
import pytz
index = pandas.date_range(start='2012-12-24 16:00', end='2012-12-24 18:00', freq='H', tz='Europe/Berlin')
ts = pandas.TimeSeries(index=index, data=index.hour)
time_pandas = pandas.Timestamp('2012-12-24 17:00', tz='Europe/Berlin')
time_datetime = datetime.datetime(2012,12,24,17,00, tzinfo=pytz.timezone('Europe/Berlin'))
time_pandas == time_datetime
ts[time_pandas] == ts[time_datetime]

While the two time stamps are equal, using them as an index on the TimeSeries results in different values. The same is true for slicing.

When using a tz-aware datetime for indexing/slicing, pandas seems to remove the timezone and interprete the time stamp as UTC.

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