Skip to content

Commit 22e2574

Browse files
committed
Merge pull request pandas-dev#82 from manahl/multiindex-metadata-check
Should check tz metadata for None for backward compatibility. Fixes pandas-dev#81
2 parents 7c694c1 + 76839c3 commit 22e2574

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

arctic/store/_pandas_ndarray_store.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def _index_from_records(self, recarr):
7272
if isinstance(rtn, DatetimeIndex) and 'index_tz' in recarr.dtype.metadata:
7373
rtn = rtn.tz_localize('UTC').tz_convert(recarr.dtype.metadata['index_tz'])
7474
elif isinstance(rtn, MultiIndex):
75-
for i, tz in enumerate(recarr.dtype.metadata.get('index_tz')):
75+
for i, tz in enumerate(recarr.dtype.metadata.get('index_tz', [])):
7676
if tz is not None:
7777
rtn.set_levels(rtn.levels[i].tz_localize('UTC').tz_convert(tz), i, inplace=True)
7878

tests/unit/store/test_pandas_ndarray_store.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from mock import Mock, sentinel, patch
2-
import numpy as np
3-
import pandas as pd
2+
from pandas.util.testing import assert_frame_equal
43
from pytest import raises
54

65
from arctic.store._pandas_ndarray_store import PandasStore, \
76
PandasDataFrameStore, PandasPanelStore
7+
import numpy as np
8+
import pandas as pd
9+
from tests.util import read_str_as_pandas
810

911

1012
def test_can_convert_to_records_without_objects_returns_false_on_exception_in_to_records():
@@ -87,3 +89,18 @@ def test_raises_upon_empty_panel_write():
8789
panel = Mock(shape=(1, 0, 3))
8890
with raises(ValueError):
8991
store.write(sentinel.mlib, sentinel.version, sentinel.symbol, panel, sentinel.prev)
92+
93+
94+
def test_read_multi_index_with_no_ts_info():
95+
# github #81: old multi-index ts would not have tz info in metadata. Ensure read is not broken
96+
df = read_str_as_pandas("""index 1 | index 2 | SPAM
97+
2012-09-08 | 2015-01-01 | 1.0
98+
2012-09-09 | 2015-01-02 | 1.1
99+
2012-10-08 | 2015-01-03 | 2.0""", num_index=2)
100+
store = PandasDataFrameStore()
101+
record = store.to_records(df)[0]
102+
103+
# now take away timezone info from metadata
104+
record = np.array(record.tolist(), dtype=np.dtype([('index 1', '<M8[ns]'), ('index 2', '<M8[ns]'), ('SPAM', '<f8')],
105+
metadata={'index': ['index 1', 'index 2'], 'columns': ['SPAM']}))
106+
assert store._index_from_records(record).equals(df.index)

0 commit comments

Comments
 (0)