Skip to content

Commit 4222ba1

Browse files
author
Scott Sanderson
committed
MAINT: Add more validation checks for h5 data.
These are good sanity checks/documentation, and they don't meaningfully impact performance.
1 parent 9e3deab commit 4222ba1

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

zipline/data/fx/hdf5.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ def version(self):
165165
def dts(self):
166166
"""Row labels for rate groups.
167167
"""
168-
return pd.DatetimeIndex(
169-
self._group[INDEX][DTS][:].astype('M8[ns]'),
170-
tz='UTC',
171-
)
168+
raw_dts = self._group[INDEX][DTS][:].astype('M8[ns]')
169+
if not is_sorted_ascending(raw_dts):
170+
raise ValueError("dts are not sorted for {}!".format(self._group))
171+
172+
return pd.DatetimeIndex(raw_dts, tz='UTC')
172173

173174
@lazyval
174175
def currencies(self):
@@ -244,6 +245,9 @@ def _check_dts(self, stored, requested):
244245
.format(request_end, data_end)
245246
)
246247

248+
if not is_sorted_ascending(requested):
249+
raise ValueError("Requested fx rates with non-ascending dts.")
250+
247251

248252
class HDF5FXRateWriter(object):
249253
"""Writer class for HDF5 files consumed by HDF5FXRateReader.
@@ -305,3 +309,7 @@ def _write_data_group(self, dts, currencies, data):
305309

306310
def _log_writing(self, *path):
307311
log.debug("Writing {}", '/'.join(path))
312+
313+
314+
def is_sorted_ascending(array):
315+
return (np.maximum.accumulate(array) <= array).all()

0 commit comments

Comments
 (0)