Skip to content

Commit 517d402

Browse files
committed
Merge pull request pandas-dev#102 from manahl/fix_pandas_write
Fix pandas write
2 parents 62c8d4b + 4388095 commit 517d402

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

arctic/tickstore/tickstore.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def _ensure_supported_dtypes(self, array):
540540

541541
def _pandas_to_bucket(self, df, symbol):
542542
start = to_dt(df.index[0].to_datetime())
543-
end = to_dt(df.index[0].to_datetime())
543+
end = to_dt(df.index[-1].to_datetime())
544544
rtn = {START: start, END: end, SYMBOL: symbol}
545545
rtn[VERSION] = CHUNK_VERSION_NUMBER
546546
rtn[COUNT] = len(df)

tests/integration/tickstore/test_ts_write.py

+27
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from arctic.date import mktz
99
from arctic.exceptions import OverlappingDataException, \
1010
NoDataFoundException
11+
from arctic.tickstore.tickstore import SYMBOL, START, END, COUNT, COLUMNS
12+
from tests.util import read_str_as_pandas
1113

1214

1315
DUMMY_DATA = [
@@ -77,3 +79,28 @@ def test_ts_write_pandas(tickstore_lib):
7779

7880
read = tickstore_lib.read('SYM', columns=None)
7981
assert_frame_equal(read, data, check_names=False)
82+
83+
84+
def test_to_bucket(tickstore_lib):
85+
bucket = tickstore_lib._to_bucket(DUMMY_DATA, 'SYM')
86+
assert bucket[SYMBOL] == 'SYM'
87+
assert bucket[START] == dt(2013, 1, 1, tzinfo=mktz('Europe/London'))
88+
assert bucket[END] == dt(2013, 7, 5, tzinfo=mktz('Europe/London'))
89+
assert bucket[COUNT] == 5
90+
91+
92+
def test_pandas_to_bucket(tickstore_lib):
93+
df = read_str_as_pandas(""" index | near
94+
2012-09-08 17:06:11 | 1.0
95+
2012-10-08 17:06:11 | 2.0
96+
2012-10-09 17:06:11 | 2.5
97+
2012-11-08 17:06:11 | 3.0""")
98+
df = df.tz_localize('UTC')
99+
bucket = tickstore_lib._pandas_to_bucket(df, 'SYM')
100+
assert bucket[SYMBOL] == 'SYM'
101+
assert bucket[START] == dt(2012, 9, 8, 17, 6, 11, tzinfo=mktz('UTC'))
102+
assert bucket[END] == dt(2012, 11, 8, 17, 6, 11, tzinfo=mktz('UTC'))
103+
assert bucket[COUNT] == 4
104+
assert len(bucket[COLUMNS]) == 1
105+
assert 'near' in bucket[COLUMNS]
106+

0 commit comments

Comments
 (0)