Skip to content

Commit

Permalink
Merge 922c1c5 into 837b1e4
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichalowicz committed Apr 1, 2020
2 parents 837b1e4 + 922c1c5 commit ae0ade8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion etc/requirements_locked.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ flask-cors==2.1.3
flask==1.1.1 # via flask-cors
funcsigs==1.0.2 # via mock, python-interface
futures==3.2.0 # via tornado
h5py==2.7.1
h5py==2.10.0
idna==2.7 # via requests
intervaltree==2.1.0
iso3166==0.9
Expand Down
27 changes: 26 additions & 1 deletion zipline/data/minute_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from lru import LRU
import bcolz
from bcolz import ctable
import h5py
from intervaltree import IntervalTree
import logbook
import numpy as np
Expand Down Expand Up @@ -1373,7 +1374,31 @@ class H5MinuteBarUpdateReader(MinuteBarUpdateReader):
The path of the HDF5 file from which to source data.
"""
def __init__(self, path):
self._panel = pd.read_hdf(path)
# There is a bug in `pandas.read_hdf` whereby in Python 3 it fails to
# read the timezone attr of an h5 file if that file was written in
# Python 2. Until zipline has dropped Python 2 entirely we are at risk
# of hitting this issue. For now, use h5py to read the file instead.
# The downside of using h5py directly is that we need to interpret the
# attrs manually when creating our panel (specifically the tz attr),
# but since we know exactly how the file was written this should be
# pretty straightforward.
with h5py.File(path, 'r') as f:
updates = f['updates']
values = updates['block0_values']
items = updates['axis0']
major = updates['axis1']
minor = updates['axis2']

self._panel = pd.Panel(
data=np.array(values).T,
items=np.array(items),
major_axis=pd.DatetimeIndex(
major,
tz=major.attrs['tz'].decode(),
freq='T',
),
minor_axis=np.array(minor).astype('U'),
)

def read(self, dts, sids):
panel = self._panel[sids, dts, :]
Expand Down

0 comments on commit ae0ade8

Please sign in to comment.