From c5efba0c8acadaa626e0930c562d74e51f5f2a70 Mon Sep 17 00:00:00 2001 From: Maya Tydykov Date: Fri, 27 Jan 2017 15:15:27 -0500 Subject: [PATCH] MAINT: make obj adjustment dispatching more granular --- zipline/lib/adjustment.pyx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/zipline/lib/adjustment.pyx b/zipline/lib/adjustment.pyx index 6df8c770..13c01280 100644 --- a/zipline/lib/adjustment.pyx +++ b/zipline/lib/adjustment.pyx @@ -4,6 +4,9 @@ from cpython cimport Py_EQ from pandas import isnull, Timestamp from numpy cimport float64_t, uint8_t, int64_t from numpy import asarray, datetime64, float64, int64 + +from zipline.utils.compat import unicode + # Purely for readability. There aren't C-level declarations for these types. ctypedef object Int64Index_t ctypedef object DatetimeIndex_t @@ -45,6 +48,9 @@ def _is_datetime(object value): def _is_int(object value): return isinstance(value, (int, int64)) +def _is_obj(object value): + return isinstance(value, (bytes, unicode, type(None))) + cpdef choose_adjustment_type(AdjustmentKind adjustment_kind, object value): """ Make an adjustment object of the type appropriate for the given kind and @@ -77,8 +83,14 @@ cpdef choose_adjustment_type(AdjustmentKind adjustment_kind, object value): return _datetime_adjustment_types[adjustment_kind] elif _is_int(value): return _int_adjustment_types[adjustment_kind] - else: + elif _is_obj(value): return _object_adjustment_types[adjustment_kind] + else: + raise TypeError( + "Don't know how to make overwrite " + "adjustments for values of type %r." % type(value), + ) + else: raise ValueError("Unknown adjustment type %d." % adjustment_kind)