Skip to content

Commit

Permalink
rolling back np.get_array()
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-jansen committed Sep 25, 2024
1 parent 1c21cb9 commit 08833bf
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/zipline/assets/_assets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions src/zipline/assets/continuous_futures.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -257,7 +256,7 @@ cdef class ContinuousFuture:

def is_exchange_open(self, dt_minute):
"""
Parameters
----------
dt_minute: pd.Timestamp (UTC, tz-aware)
Expand Down
2 changes: 0 additions & 2 deletions src/zipline/data/_adjustments.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/zipline/data/_equities.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/zipline/data/_minute_bar_internal.pyx
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/zipline/data/_resample.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/zipline/gens/sim_engine.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 3 additions & 14 deletions src/zipline/lib/_factorize.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
"""
Expand All @@ -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.
"""
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion src/zipline/lib/_float64window.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 0 additions & 1 deletion src/zipline/lib/_int64window.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
datetime specialization of AdjustedArrayWindow
"""
from numpy cimport int64_t
import numpy; numpy.import_array()

ctypedef int64_t[:, :] databuffer

Expand Down
1 change: 0 additions & 1 deletion src/zipline/lib/_uint8window.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
bool specialization of AdjustedArrayWindow
"""
from numpy cimport uint8_t
import numpy; numpy.import_array()

ctypedef uint8_t[:, :] databuffer

Expand Down
3 changes: 1 addition & 2 deletions src/zipline/lib/adjustment.pyx
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 1 addition & 2 deletions src/zipline/lib/rank.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/zipline/utils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 08833bf

Please sign in to comment.