diff --git a/zipline/lib/_factorize.pyx b/zipline/lib/_factorize.pyx index 390266ed..a90cec9f 100644 --- a/zipline/lib/_factorize.pyx +++ b/zipline/lib/_factorize.pyx @@ -1,7 +1,7 @@ """ Factorization algorithms. """ -from libc.math cimport floor +from libc.math cimport floor, log cimport numpy as np import numpy as np @@ -10,14 +10,8 @@ from zipline.utils.numpy_utils import unsigned_int_dtype_with_size_in_bytes np.import_array() -IF UNAME_SYSNAME == "Windows": - # msvc doesn't define log2 - from libc.math cimport log - - cdef double log2(double d): - return log(d) / log(2); -ELSE: - from libc.math cimport log2 +cdef inline double log2(double d): + return log(d) / log(2); ctypedef fused unsigned_integral: diff --git a/zipline/lib/labelarray.py b/zipline/lib/labelarray.py index a6db0267..c9db21e6 100644 --- a/zipline/lib/labelarray.py +++ b/zipline/lib/labelarray.py @@ -176,7 +176,7 @@ class LabelArray(ndarray): ) categories.setflags(write=False) - return cls._from_codes_and_metadata( + return cls.from_codes_and_metadata( codes=codes.reshape(values.shape), categories=categories, reverse_categories=reverse_categories, @@ -184,13 +184,24 @@ class LabelArray(ndarray): ) @classmethod - def _from_codes_and_metadata(cls, - codes, - categories, - reverse_categories, - missing_value): + def from_codes_and_metadata(cls, + codes, + categories, + reverse_categories, + missing_value): """ - View codes as a LabelArray and set LabelArray metadata on the result. + Rehydrate a LabelArray from the codes and metadata. + + Parameters + ---------- + codes : np.ndarray[integral] + The codes for the label array. + categories : np.ndarray[object] + The unique string categories. + reverse_categories : dict[str, int] + The mapping from category to its code-index. + missing_value : any + The value used to represent missing data. """ ret = codes.view(type=cls, dtype=np.void) ret._categories = categories @@ -517,7 +528,7 @@ class LabelArray(ndarray): Make an empty LabelArray with the same categories as ``self``, filled with ``self.missing_value``. """ - return type(self)._from_codes_and_metadata( + return type(self).from_codes_and_metadata( codes=np.full( shape, self.reverse_categories[self.missing_value],