-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Construct Timestamp with tz correctly near DST border #21407
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 4 commits
c5566d5
5d207ea
f4eb827
c8dabe1
795cc39
f171f9f
7e183a8
3dd00d7
ae9dc7b
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
# cython: profile=False | ||
|
||
from warnings import catch_warnings | ||
|
||
cimport cython | ||
from cython cimport Py_ssize_t | ||
|
||
|
@@ -347,9 +349,14 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz, | |
if tz is not None: | ||
tz = maybe_get_tz(tz) | ||
|
||
# sort of a temporary hack | ||
if ts.tzinfo is not None: | ||
if hasattr(tz, 'normalize') and hasattr(ts.tzinfo, '_utcoffset'): | ||
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. This check might be superfluous since 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. hmm, you can try that and see if it works. maybe add a comment anyhow |
||
# tz.localize does not correctly localize Timestamps near DST | ||
# but correctly localizes datetimes | ||
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. IIRC |
||
if hasattr(ts, 'to_pydatetime'): | ||
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. Elsewhere we've used 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. Thanks @jbrockmendel. Seems clearer than trying to get |
||
nanos += ts.nanosecond | ||
with catch_warnings(record=True): | ||
ts = ts.to_pydatetime() | ||
ts = tz.normalize(ts) | ||
obj.value = pydatetime_to_dt64(ts, &obj.dts) | ||
obj.tzinfo = ts.tzinfo | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -992,6 +992,16 @@ def test_boolean_comparison(self): | |
result = df == tup | ||
assert_frame_equal(result, expected) | ||
|
||
@pytest.mark.parametrize('tz', [None, 'America/New_York']) | ||
def test_boolean_compare_transpose_tzindex_with_dst(self, tz): | ||
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 move to test_timezones |
||
# GH 19970 | ||
idx = date_range('20161101', '20161130', freq='4H', tz=tz) | ||
df = DataFrame({'a': range(len(idx)), 'b': range(len(idx))}, | ||
index=idx) | ||
result = df.T == df.T | ||
expected = DataFrame(True, index=list('ab'), columns=idx) | ||
assert_frame_equal(result, expected) | ||
|
||
def test_combine_generic(self): | ||
df1 = self.frame | ||
df2 = self.frame.loc[self.frame.index[:-5], ['A', 'B', 'C']] | ||
|
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.
move to 0.23.2