TsTables: AttributeError: module 'pandas.tseries' has no attribute 'index'

Viewed 264

Background I have a DataFrame which I am trying to write/append to a TsTable. I am executing it using Jupyter notebook. Python 3.9.7.

Problem I am getting an error while trying to append.

DataFrame structure

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 5000000 entries, 2019-01-01 00:00:00 to 2019-02-27 20:53:19
Freq: S
Data columns (total 3 columns):
    Column  Dtype  
---  ------  -----  
 0   ts1     float64
 1   ts2     float64
 2   ts3     float64
dtypes: float64(3)

Code (Ref: Python for Finance by Yves Hilpisch)

import tstables as tstab

class ts_desc(tb.IsDescription):
    timestamp = tb.Int64Col(pos=0)
    ts1 = tb.Float64Col(pos=1)
    ts2 = tb.Float64Col(pos=2)
    ts3 = tb.Float64Col(pos=3)

h5 = tb.open_file(path + 'tstab.h5', 'w')

ts = h5.create_ts('/', 'ts', ts_desc) # create a TsTable object based on the ts_dsc object

%time ts.append(df) # append the data from the DataFrame object to TsTable object

The error happens after the above command.

AttributeError                            Traceback (most recent call last)
<timed eval> in <module>

/opt/conda/lib/python3.9/site-packages/tstables/tstable.py in append(self, rows, convert_strings)
    237             if rows.empty:
    238                 return # Do nothing if we are appending nothing
--> 239             if rows.index.__class__ != pandas.tseries.index.DatetimeIndex:
    240                 raise ValueError('when rows is a DataFrame, the index must be a DatetimeIndex.')
    241 

AttributeError: module 'pandas.tseries' has no attribute 'index'
1 Answers

You should use this code before your first import:

pip install git+https://github.com/yhilpisch/tstables.git

with this version of tstables, your code works well.

Related