@@ -509,7 +509,8 @@ def write(self, symbol, data, initial_image=None):
509
509
data : list of dicts or a pandas.DataFrame
510
510
List of ticks to store to the tick-store.
511
511
if a list of dicts, each dict must contain a 'index' datetime
512
- if a pandas.DataFrame the index must be a Timestamp that can be converted to a datetime
512
+ if a pandas.DataFrame the index must be a Timestamp that can be converted to a datetime.
513
+ Index names will not be preserved.
513
514
initial_image : dict
514
515
Dict of the initial image at the start of the document. If this contains a 'index' entry it is
515
516
assumed to be the time of the timestamp of the index
@@ -628,6 +629,7 @@ def _pandas_to_bucket(df, symbol, initial_image):
628
629
logger .warning ("NB treating all values as 'exists' - no longer sparse" )
629
630
rowmask = Binary (lz4 .compressHC (np .packbits (np .ones (len (df ), dtype = 'uint8' ))))
630
631
632
+ index_name = df .index .names [0 ] or "index"
631
633
recs = df .to_records (convert_datetime64 = False )
632
634
for col in df :
633
635
array = TickStore ._ensure_supported_dtypes (recs [col ])
@@ -636,9 +638,8 @@ def _pandas_to_bucket(df, symbol, initial_image):
636
638
col_data [ROWMASK ] = rowmask
637
639
col_data [DTYPE ] = TickStore ._str_dtype (array .dtype )
638
640
rtn [COLUMNS ][col ] = col_data
639
- rtn [INDEX ] = Binary (lz4 .compressHC (np .concatenate (([recs ['index' ][0 ].astype ('datetime64[ms]' ).view ('uint64' )],
640
- np .diff (recs ['index' ].astype ('datetime64[ms]' ).view ('uint64' )))
641
- ).tostring ()))
641
+ rtn [INDEX ] = Binary (lz4 .compressHC (np .concatenate (([recs [index_name ][0 ].astype ('datetime64[ms]' ).view ('uint64' )],
642
+ np .diff (recs [index_name ].astype ('datetime64[ms]' ).view ('uint64' )))).tostring ()))
642
643
return rtn , final_image
643
644
644
645
@staticmethod
0 commit comments