-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Recognize timezoned labels when accessing dataframes. #17920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
4671aeb
2297833
69b517e
6532e76
c354271
a9202fb
88bf001
7d8c9ab
1310680
46d9416
c8a604e
de7a065
7c0a3be
8844b2e
62695a2
7691209
edad476
bd958a1
ef9a06c
ba279c0
2a31f7b
aa5ea0f
4bfbca9
dd761d3
a6353dd
c440981
2c3faad
fff48bb
00f61bb
69a3b06
ffd363b
8587a3d
763b5f7
9456b77
fd49175
d944bfd
1641bf2
f12caa1
1a3ab3b
31ef655
edfd895
fbf8a1c
9f0dc5d
817bfef
5c11e02
6a218e5
577d742
931b7f9
02aa59f
0e4c499
16fe3c3
5724292
a4f3a5c
8a2176d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,6 +123,30 @@ def test_consistency_with_tz_aware_scalar(self): | |
result = df[0].at[0] | ||
assert result == expected | ||
|
||
def test_access_datetimeindex_with_timezoned_label(self): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add the github issue number here as a comment? (see the test after this one for an example) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added now. |
||
idx = pd.DataFrame(index=pd.date_range('2016-01-01T00:00', '2016-03-31T23:59', freq='T')) | ||
|
||
former_naive_endpoint_idx = idx[ | ||
"2016-01-01T00:00-02:00" | ||
: | ||
"2016-01-01T02:03" | ||
] | ||
|
||
former_non_naive_endpoint_idx = idx[ | ||
pd.Timestamp("2016-01-01T00:00-02:00") | ||
: | ||
pd.Timestamp("2016-01-01T02:03") | ||
] | ||
|
||
assert len(former_naive_endpoint_idx) == len(former_non_naive_endpoint_idx) | ||
|
||
assert former_naive_endpoint_idx.iloc[0].name == former_non_naive_endpoint_idx.iloc[0].name | ||
assert former_naive_endpoint_idx.iloc[1].name == former_non_naive_endpoint_idx.iloc[1].name | ||
assert former_naive_endpoint_idx.iloc[2].name == former_non_naive_endpoint_idx.iloc[2].name | ||
assert former_naive_endpoint_idx.iloc[3].name == former_non_naive_endpoint_idx.iloc[3].name | ||
|
||
|
||
def test_indexing_with_datetimeindex_tz(self): | ||
|
||
# GH 12050 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so you need to do something different here. leave the dates that are generated in the current tz (e.g.
self.tz
). Then you need to convert it to the parsed_tz, BUT then you need to localize back into the original timezone. There are a number of cases, here's an example.As I am writing this, it looks overly complicated. I might choose instead to raise if the timezones don't match (they can be same tz or both None).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I elaborated in #16785 the timezones do not need to match. There are quite usual cases with daylight savings time that require some flexibility here. So my idea is to change
target_tz = parsed.tzinfo
to some kind of conversion which you mentioned. Next week I might give it a shot. Dealing with only the timezone of the DatetimeIndex seems reasonable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really tired but tried to find a solution. If it works, great, if not, at least it shows the idea. I will come back to it as soon as possible. Now I am having some issues with installing the development environment under Windows 10 and all solutions found look quite time consuming. Sorry when I spam you with not working code.