Skip to content

Commit 9e3deab

Browse files
author
Scott Sanderson
committed
MAINT: Store and validate file version for h5 fx data.
1 parent 006b7b9 commit 9e3deab

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

zipline/data/fx/hdf5.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105

106106
from .base import FXRateReader, DEFAULT_FX_RATE
107107

108+
HDF5_FX_VERSION = 0
109+
108110
INDEX = 'index'
109111
DATA = 'data'
110112
CURRENCIES = 'currencies'
@@ -129,6 +131,13 @@ def __init__(self, group, default_rate):
129131
self._group = group
130132
self._default_rate = default_rate
131133

134+
if self.version != HDF5_FX_VERSION:
135+
raise ValueError(
136+
"FX Reader version ({}) != File Version ({})".format(
137+
HDF5_FX_VERSION, self.version,
138+
)
139+
)
140+
132141
@classmethod
133142
def from_path(cls, path, default_rate):
134143
"""
@@ -144,6 +153,14 @@ def from_path(cls, path, default_rate):
144153
"""
145154
return cls(h5py.File(path), default_rate=default_rate)
146155

156+
@lazyval
157+
def version(self):
158+
try:
159+
return self._group.attrs['version']
160+
except KeyError:
161+
# TODO: Remove this.
162+
return 0
163+
147164
@lazyval
148165
def dts(self):
149166
"""Row labels for rate groups.
@@ -249,9 +266,14 @@ def write(self, dts, currencies, data):
249266
contain a table of rates where each column is a timeseries of rates
250267
mapping its column label's currency to ``quote_currency``.
251268
"""
269+
self._write_metadata()
252270
self._write_index_group(dts, currencies)
253271
self._write_data_group(dts, currencies, data)
254272

273+
def _write_metadata(self):
274+
self._group.attrs['version'] = HDF5_FX_VERSION
275+
self._group.attrs['last_updated_utc'] = str(pd.Timestamp.utcnow())
276+
255277
def _write_index_group(self, dts, currencies):
256278
"""Write content of /index.
257279
"""

0 commit comments

Comments
 (0)