diff --git a/src/zipline/assets/_assets.pyx b/src/zipline/assets/_assets.pyx index 69de80f504..3791e3d1d8 100644 --- a/src/zipline/assets/_assets.pyx +++ b/src/zipline/assets/_assets.pyx @@ -33,7 +33,7 @@ import numpy as np from numpy cimport int64_t import warnings cimport numpy as np -import numpy; numpy.import_array() + from zipline.utils.calendar_utils import get_calendar diff --git a/src/zipline/assets/continuous_futures.pyx b/src/zipline/assets/continuous_futures.pyx index 496b879a0f..718bbd445e 100644 --- a/src/zipline/assets/continuous_futures.pyx +++ b/src/zipline/assets/continuous_futures.pyx @@ -26,15 +26,14 @@ from cpython.object cimport ( Py_GT, Py_LT, ) -from cpython cimport bool -import numpy; numpy.import_array() +# from cpython cimport bool from functools import partial from numpy import array, empty, iinfo from numpy cimport int64_t, int64_t from pandas import Timestamp from zipline.utils.calendar_utils import get_calendar -import warnings +# import warnings def delivery_predicate(codes, contract): @@ -257,7 +256,7 @@ cdef class ContinuousFuture: def is_exchange_open(self, dt_minute): """ - + Parameters ---------- dt_minute: pd.Timestamp (UTC, tz-aware) diff --git a/src/zipline/data/_adjustments.pyx b/src/zipline/data/_adjustments.pyx index 458bc17618..a85ba462c1 100644 --- a/src/zipline/data/_adjustments.pyx +++ b/src/zipline/data/_adjustments.pyx @@ -25,8 +25,6 @@ from numpy import ( zeros, ) from numpy cimport float64_t, int64_t, ndarray -import numpy -numpy.import_array() from pandas import Timestamp ctypedef object Timestamp_t diff --git a/src/zipline/data/_equities.pyx b/src/zipline/data/_equities.pyx index 784e2351f6..a480a24397 100644 --- a/src/zipline/data/_equities.pyx +++ b/src/zipline/data/_equities.pyx @@ -32,7 +32,6 @@ from numpy cimport ( uint8_t, ) from numpy.math cimport NAN -import numpy; numpy.import_array() ctypedef object carray_t ctypedef object ctable_t ctypedef object Timestamp_t diff --git a/src/zipline/data/_minute_bar_internal.pyx b/src/zipline/data/_minute_bar_internal.pyx index 76788f5aa7..8dee07b2da 100644 --- a/src/zipline/data/_minute_bar_internal.pyx +++ b/src/zipline/data/_minute_bar_internal.pyx @@ -1,5 +1,4 @@ from numpy cimport ndarray, int64_t -import numpy; numpy.import_array() from numpy import searchsorted from cpython cimport bool cimport cython diff --git a/src/zipline/data/_resample.pyx b/src/zipline/data/_resample.pyx index d79771890f..0e336f6d60 100644 --- a/src/zipline/data/_resample.pyx +++ b/src/zipline/data/_resample.pyx @@ -14,7 +14,7 @@ from cython cimport boundscheck, wraparound from numpy import finfo, float64, nan, isnan from numpy cimport intp_t, float64_t, uint32_t -import numpy; numpy.import_array() + @boundscheck(False) @wraparound(False) diff --git a/src/zipline/gens/sim_engine.pyx b/src/zipline/gens/sim_engine.pyx index a8eb51bc24..b15a70fcc9 100644 --- a/src/zipline/gens/sim_engine.pyx +++ b/src/zipline/gens/sim_engine.pyx @@ -15,7 +15,6 @@ cimport cython cimport numpy as np -import numpy; numpy.import_array() import numpy as np import pandas as pd from cpython cimport bool diff --git a/src/zipline/lib/_factorize.pyx b/src/zipline/lib/_factorize.pyx index 5e269d2392..4d448da56d 100644 --- a/src/zipline/lib/_factorize.pyx +++ b/src/zipline/lib/_factorize.pyx @@ -5,17 +5,13 @@ from cpython cimport Py_LT from libc.math cimport log cimport numpy as np import numpy as np -np.import_array() -from zipline.utils.numpy_utils import unsigned_int_dtype_with_size_in_bytes - -np.import_array() +from zipline.utils.numpy_utils import unsigned_int_dtype_with_size_in_bytes cdef inline double log2(double d): return log(d) / log(2); - cpdef inline smallest_uint_that_can_hold(Py_ssize_t maxval): """Choose the smallest numpy unsigned int dtype that can hold ``maxval``. """ @@ -32,14 +28,12 @@ cpdef inline smallest_uint_that_can_hold(Py_ssize_t maxval): _int_sizes[int(np.ceil(log2(maxval) / 8))] ) - ctypedef fused unsigned_integral: np.uint8_t np.uint16_t np.uint32_t np.uint64_t - cdef class _NoneFirstSortKey: """Box to sort ``None`` to the front of the categories list. """ @@ -51,13 +45,12 @@ cdef class _NoneFirstSortKey: def __richcmp__(_NoneFirstSortKey self, _NoneFirstSortKey other, int op): if op == Py_LT: return ( - self.value is None or - (other.value is not None and self.value < other.value) + self.value is None or + (other.value is not None and self.value < other.value) ) return NotImplemented - cdef factorize_strings_known_impl(np.ndarray[object] values, Py_ssize_t nvalues, list categories, @@ -78,7 +71,6 @@ cdef factorize_strings_known_impl(np.ndarray[object] values, return codes, np.asarray(categories, dtype=object), reverse_categories - cpdef factorize_strings_known_categories(np.ndarray[object] values, list categories, object missing_value, @@ -133,7 +125,6 @@ cpdef factorize_strings_known_categories(np.ndarray[object] values, else: raise ValueError('ncategories larger than uint64') - cdef factorize_strings_impl(np.ndarray[object] values, object missing_value, bint sort, @@ -181,10 +172,8 @@ cdef factorize_strings_impl(np.ndarray[object] values, return codes, categories_array, reverse_categories - cdef list _int_sizes = [1, 1, 2, 4, 4, 8, 8, 8, 8] - cpdef factorize_strings(np.ndarray[object] values, object missing_value, int sort): diff --git a/src/zipline/lib/_float64window.pyx b/src/zipline/lib/_float64window.pyx index 07c279d625..1747b014e3 100644 --- a/src/zipline/lib/_float64window.pyx +++ b/src/zipline/lib/_float64window.pyx @@ -2,7 +2,6 @@ float specialization of AdjustedArrayWindow """ from numpy cimport float64_t -import numpy; numpy.import_array() ctypedef float64_t[:, :] databuffer include "_windowtemplate.pxi" diff --git a/src/zipline/lib/_int64window.pyx b/src/zipline/lib/_int64window.pyx index 84b8b56467..d30b97cac4 100644 --- a/src/zipline/lib/_int64window.pyx +++ b/src/zipline/lib/_int64window.pyx @@ -2,7 +2,6 @@ datetime specialization of AdjustedArrayWindow """ from numpy cimport int64_t -import numpy; numpy.import_array() ctypedef int64_t[:, :] databuffer diff --git a/src/zipline/lib/_uint8window.pyx b/src/zipline/lib/_uint8window.pyx index 7e2aeb4756..8b8ce98b2b 100644 --- a/src/zipline/lib/_uint8window.pyx +++ b/src/zipline/lib/_uint8window.pyx @@ -2,7 +2,6 @@ bool specialization of AdjustedArrayWindow """ from numpy cimport uint8_t -import numpy; numpy.import_array() ctypedef uint8_t[:, :] databuffer diff --git a/src/zipline/lib/adjustment.pyx b/src/zipline/lib/adjustment.pyx index 71c4872fb4..be42ab646c 100644 --- a/src/zipline/lib/adjustment.pyx +++ b/src/zipline/lib/adjustment.pyx @@ -1,12 +1,11 @@ # cython: embedsignature=True from cpython cimport Py_EQ -cimport cython +# cimport cython from pandas import isnull, Timestamp cimport numpy as np from numpy cimport float64_t, uint8_t, int64_t from numpy import asarray, datetime64, float64, int64, bool_, uint8 -import numpy; numpy.import_array() from zipline.utils.compat import unicode diff --git a/src/zipline/lib/rank.pyx b/src/zipline/lib/rank.pyx index d807276d3b..0128415c71 100644 --- a/src/zipline/lib/rank.pyx +++ b/src/zipline/lib/rank.pyx @@ -2,9 +2,8 @@ Functions for ranking and sorting. """ cimport cython -cimport numpy as np -import numpy; numpy.import_array() import numpy as np +cimport numpy as np from cpython cimport bool from scipy.stats import rankdata from zipline.utils.numpy_utils import is_missing diff --git a/src/zipline/utils/cache.py b/src/zipline/utils/cache.py index 3d220421dd..9bed4fa1c9 100644 --- a/src/zipline/utils/cache.py +++ b/src/zipline/utils/cache.py @@ -5,7 +5,9 @@ from functools import partial import os import pickle -from distutils import dir_util + +# from distutils import dir_util +from shutil import copytree from shutil import rmtree, move from tempfile import mkdtemp, NamedTemporaryFile @@ -371,7 +373,7 @@ def getpath(self, *path_parts): def _commit(self): """Sync the temporary directory to the final path.""" - dir_util.copy_tree(self.path, self._final_path) + copytree(src=self.path, dst=self._final_path, dirs_exist_ok=True) def __enter__(self): return self