-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Support dateutil timezones. GH4688. #6968
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 all commits
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 |
---|---|---|
|
@@ -1991,7 +1991,7 @@ def test_unimplemented_dtypes_table_columns(self): | |
# this fails because we have a date in the object block...... | ||
self.assertRaises(TypeError, store.append, 'df_unimplemented', df) | ||
|
||
def test_append_with_timezones(self): | ||
def test_append_with_timezones_pytz(self): | ||
|
||
from datetime import timedelta | ||
|
||
|
@@ -2020,7 +2020,8 @@ def compare(a,b): | |
compare(store.select('df_tz',where=Term('A>=df.A[3]')),df[df.A>=df.A[3]]) | ||
|
||
_maybe_remove(store, 'df_tz') | ||
df = DataFrame(dict(A = Timestamp('20130102',tz='US/Eastern'), B = Timestamp('20130103',tz='US/Eastern')),index=range(5)) | ||
# ensure we include dates in DST and STD time here. | ||
df = DataFrame(dict(A = Timestamp('20130102',tz='US/Eastern'), B = Timestamp('20130603',tz='US/Eastern')),index=range(5)) | ||
store.append('df_tz',df) | ||
result = store['df_tz'] | ||
compare(result,df) | ||
|
@@ -2057,6 +2058,78 @@ def compare(a,b): | |
result = store.select('df') | ||
assert_frame_equal(result,df) | ||
|
||
def test_append_with_timezones_dateutil(self): | ||
|
||
from datetime import timedelta | ||
|
||
try: | ||
import dateutil | ||
except ImportError: | ||
raise nose.SkipTest | ||
|
||
def compare(a, b): | ||
tm.assert_frame_equal(a, b) | ||
|
||
# compare the zones on each element | ||
for c in a.columns: | ||
for i in a.index: | ||
a_e = a[c][i] | ||
b_e = b[c][i] | ||
if not (a_e == b_e and a_e.tz == b_e.tz): | ||
raise AssertionError("invalid tz comparsion [%s] [%s]" % (a_e, b_e)) | ||
|
||
# as columns | ||
with ensure_clean_store(self.path) as store: | ||
|
||
_maybe_remove(store, 'df_tz') | ||
df = DataFrame(dict(A=[ Timestamp('20130102 2:00:00', tz=dateutil.tz.gettz('US/Eastern')) + timedelta(hours=1) * i for i in range(5) ])) | ||
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. do these tz's actually store differently? (except that they use the dateutil tzs 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.
This is just a duplicate of the original test (test_append_with_timezones_pytz) but using |
||
store.append('df_tz', df, data_columns=['A']) | ||
result = store['df_tz'] | ||
compare(result, df) | ||
assert_frame_equal(result, df) | ||
|
||
# select with tz aware | ||
compare(store.select('df_tz', where=Term('A>=df.A[3]')), df[df.A >= df.A[3]]) | ||
|
||
_maybe_remove(store, 'df_tz') | ||
# ensure we include dates in DST and STD time here. | ||
df = DataFrame(dict(A=Timestamp('20130102', tz=dateutil.tz.gettz('US/Eastern')), B=Timestamp('20130603', tz=dateutil.tz.gettz('US/Eastern'))), index=range(5)) | ||
store.append('df_tz', df) | ||
result = store['df_tz'] | ||
compare(result, df) | ||
assert_frame_equal(result, df) | ||
|
||
_maybe_remove(store, 'df_tz') | ||
df = DataFrame(dict(A=Timestamp('20130102', tz=dateutil.tz.gettz('US/Eastern')), B=Timestamp('20130102', tz=dateutil.tz.gettz('EET'))), index=range(5)) | ||
self.assertRaises(TypeError, store.append, 'df_tz', df) | ||
|
||
# this is ok | ||
_maybe_remove(store, 'df_tz') | ||
store.append('df_tz', df, data_columns=['A', 'B']) | ||
result = store['df_tz'] | ||
compare(result, df) | ||
assert_frame_equal(result, df) | ||
|
||
# can't append with diff timezone | ||
df = DataFrame(dict(A=Timestamp('20130102', tz=dateutil.tz.gettz('US/Eastern')), B=Timestamp('20130102', tz=dateutil.tz.gettz('CET'))), index=range(5)) | ||
self.assertRaises(ValueError, store.append, 'df_tz', df) | ||
|
||
# as index | ||
with ensure_clean_store(self.path) as store: | ||
|
||
# GH 4098 example | ||
df = DataFrame(dict(A=Series(lrange(3), index=date_range('2000-1-1', periods=3, freq='H', tz=dateutil.tz.gettz('US/Eastern'))))) | ||
|
||
_maybe_remove(store, 'df') | ||
store.put('df', df) | ||
result = store.select('df') | ||
assert_frame_equal(result, df) | ||
|
||
_maybe_remove(store, 'df') | ||
store.append('df', df) | ||
result = store.select('df') | ||
assert_frame_equal(result, df) | ||
|
||
def test_store_timezone(self): | ||
# GH2852 | ||
# issue storing datetime.date with a timezone as it resets when read back in a new timezone | ||
|
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.
can you add a note (about why one would choose to use
dateutil
overpytz
(the default)?