Skip to content

Commit 644940a

Browse files
authored
Fix issues with pandas 0.23 (pandas-dev#567)
* fixes for latest version of pandas * assume missing timezone is local * latest pytest breaks tests
1 parent 4b1d479 commit 644940a

File tree

6 files changed

+11
-9
lines changed

6 files changed

+11
-9
lines changed

arctic/multi_index.py

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66

77
from pandas import to_datetime as dt
8+
from .date import mktz
89

910
import numpy as np
1011
import pandas as pd
@@ -90,6 +91,9 @@ def groupby_asof(df, as_of=None, dt_col='sample_dt', asof_col='observed_dt'):
9091
asof_col: ``str`` or ``int``
9192
Name or index of the column in the MultiIndex that is the observed date
9293
'''
94+
if as_of:
95+
if as_of.tzinfo is None and df.index.get_level_values(asof_col).tz is not None:
96+
as_of = as_of.replace(tzinfo=mktz())
9397
return fancy_group_by(df,
9498
grouping_level=dt_col,
9599
aggregate_level=asof_col,

arctic/tickstore/tickstore.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def read(self, symbol, date_range=None, columns=None, include_images=False, allo
339339
mgr = _arrays_to_mgr(arrays, columns, index, columns, dtype=None)
340340
rtn = pd.DataFrame(mgr)
341341
# Present data in the user's default TimeZone
342-
rtn.index.tz = mktz()
342+
rtn.index.tz_convert(mktz())
343343

344344
t = (dt.now() - perf_start).total_seconds()
345345
ticks = len(rtn)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def extensions():
158158
],
159159
tests_require=["mock",
160160
"mockextras",
161-
"pytest",
161+
"pytest<=3.5.1",
162162
"pytest-cov",
163163
"pytest-server-fixtures",
164164
"pytest-timeout",

tests/integration/store/test_bitemporal_store.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@author: ateng
55
'''
66
from datetime import datetime as dt
7+
import pytz
78

89
from mock import patch
910
from pandas.util.testing import assert_frame_equal
@@ -93,8 +94,7 @@ def test_read_ts_with_historical_update(bitemporal_library):
9394
bitemporal_library.update('spam', read_str_as_pandas(""" sample_dt | near
9495
2012-10-09 17:06:11.040 | 6.6"""),
9596
as_of=dt(2015, 5, 3))
96-
97-
assert_frame_equal(bitemporal_library.read('spam', as_of=dt(2015, 5, 2, 10)).data, read_str_as_pandas(
97+
assert_frame_equal(bitemporal_library.read('spam', as_of=dt(2015, 5, 2, 10, tzinfo=pytz.timezone("Europe/London"))).data, read_str_as_pandas(
9898
"""sample_dt | near
9999
2012-09-08 17:06:11.040 | 1.0
100100
2012-10-08 17:06:11.040 | 2.0
@@ -107,7 +107,7 @@ def test_read_ts_with_historical_update(bitemporal_library):
107107
2012-10-09 17:06:11.040 | 6.6
108108
2012-11-08 17:06:11.040 | 3.0"""))
109109

110-
assert_frame_equal(bitemporal_library.read('spam', as_of=dt(2015, 5, 1, 10)).data, ts1)
110+
assert_frame_equal(bitemporal_library.read('spam', as_of=dt(2015, 5, 1, 10, tzinfo=pytz.timezone("Europe/London"))).data, ts1)
111111

112112

113113
def test_read_ts_with_historical_update_and_new_row(bitemporal_library):

tests/integration/tickstore/test_ts_read.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_read_all_cols_all_dtypes(tickstore_lib, chunk_size):
193193
index = DatetimeIndex([dt(1970, 1, 1, tzinfo=mktz('UTC')),
194194
dt(1970, 1, 1, 0, 0, 1, tzinfo=mktz('UTC'))],
195195
)
196-
index.tz = mktz()
196+
df.index = df.index.tz_convert(mktz('UTC'))
197197
expected = pd.DataFrame(data, index=index)
198198
expected = expected[df.columns]
199199
assert_frame_equal(expected, df, check_names=False)
@@ -322,8 +322,6 @@ def test_date_range_default_timezone(tickstore_lib, tz_name):
322322
df = tickstore_lib.read('SYM', date_range=DateRange(20130101, 20130701), columns=None)
323323
assert len(df) == 2
324324
assert df.index[1] == dt(2013, 7, 1, tzinfo=mktz(tz_name))
325-
assert df.index.tz == mktz(tz_name)
326-
327325
df = tickstore_lib.read('SYM', date_range=DateRange(20130101, 20130101), columns=None)
328326
assert len(df) == 1
329327

tests/integration/tickstore/test_ts_write.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,4 @@ def test_millisecond_roundtrip(tickstore_lib):
107107
dt(2004, 1, 15, tzinfo=pytz.utc))
108108
reread = tickstore_lib.read('blah', data_range)
109109

110-
assert reread.index[0].to_datetime() == test_time
110+
assert reread.index[0].to_pydatetime() == test_time

0 commit comments

Comments
 (0)