Skip to content

BUG: Slicing and setitem inconsistent with getitem using DateTimeIndex with timezone #2788

Closed
@stephenwlin

Description

@stephenwlin

__getitem__ with date string key interprets a string label in the index's timezone when none provided, but __getitem__ with date string slices and __setitem__ with string label/slices do not

In [1]: import pandas as p

In [2]: import numpy as np

In [3]: index=p.date_range("2012-01-01", "2012-01-02",
   ...:                    freq='60min', tz='US/Eastern')

In [4]: ts=p.Series(np.random.randn(len(index)), index)

In [5]: ts["2012-01-01 15:00:00":"2012-01-02 01:00:00"] \
   ...:     # off by five hours
Out[5]: 
2012-01-01 10:00:00-05:00   -1.294343
2012-01-01 11:00:00-05:00   -0.091218
2012-01-01 12:00:00-05:00    0.049017
2012-01-01 13:00:00-05:00   -1.068893
2012-01-01 14:00:00-05:00   -0.470317
2012-01-01 15:00:00-05:00    0.894762
2012-01-01 16:00:00-05:00    0.223070
2012-01-01 17:00:00-05:00   -0.414907
2012-01-01 18:00:00-05:00   -0.925703
2012-01-01 19:00:00-05:00    0.879205
2012-01-01 20:00:00-05:00   -1.580123
Freq: 60T

In [6]: ts["2012-01-01 20:00:00"] # ok
Out[6]: -1.5801231823927993

In [7]: ts["2012-01-01 15:00:00"] # ok
Out[7]: 0.89476211630990787

In [8]: ts["2012-01-01 20:00:00"] = 1 # off by five hours

In [9]: ts["2012-01-01 20:00:00"]
Out[9]: -1.5801231823927993

In [10]: ts["2012-01-01 15:00:00"]
Out[10]: 1.0

In [11]: ts["2012-01-01 20:00:00-05:00"] = 1 # ok

In [12]: ts["2012-01-01 20:00:00"]
Out[12]: 1.0

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