forked from scrtlabs/catalyst
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAINT: Upgrade numpy and fix warnings.
Mostly fixes ambiguous calls to numpy.full, and uses explicitly-united NaT values.
- Loading branch information
1 parent
b651993
commit 5f49fa2
Showing
15 changed files
with
152 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
join, | ||
) | ||
from distutils.version import StrictVersion | ||
from pkg_resources import resource_filename | ||
from setuptools import ( | ||
Extension, | ||
find_packages, | ||
|
@@ -33,43 +34,65 @@ | |
import versioneer | ||
|
||
|
||
class LazyCythonizingList(list): | ||
cythonized = False | ||
|
||
def lazy_cythonize(self): | ||
if self.cythonized: | ||
return | ||
self.cythonized = True | ||
|
||
from Cython.Build import cythonize | ||
from numpy import get_include | ||
|
||
self[:] = cythonize( | ||
[ | ||
Extension(*ext_args, include_dirs=[get_include()]) | ||
for ext_args in self | ||
] | ||
class LazyBuildExtCommandClass(dict): | ||
""" | ||
Lazy command class that defers operations requiring Cython and numpy until | ||
they've actually been downloaded and installed by setup_requires. | ||
""" | ||
def __contains__(self, key): | ||
return ( | ||
key == 'build_ext' | ||
or super(LazyBuildExtCommandClass, self).__contains__(key) | ||
) | ||
|
||
def __iter__(self): | ||
self.lazy_cythonize() | ||
return super(LazyCythonizingList, self).__iter__() | ||
|
||
def __getitem__(self, num): | ||
self.lazy_cythonize() | ||
return super(LazyCythonizingList, self).__getitem__(num) | ||
|
||
|
||
ext_modules = LazyCythonizingList([ | ||
('zipline.assets._assets', ['zipline/assets/_assets.pyx']), | ||
('zipline.lib.adjustment', ['zipline/lib/adjustment.pyx']), | ||
('zipline.lib._float64window', ['zipline/lib/_float64window.pyx']), | ||
('zipline.lib._int64window', ['zipline/lib/_int64window.pyx']), | ||
('zipline.lib._uint8window', ['zipline/lib/_uint8window.pyx']), | ||
('zipline.lib.rank', ['zipline/lib/rank.pyx']), | ||
('zipline.data._equities', ['zipline/data/_equities.pyx']), | ||
('zipline.data._adjustments', ['zipline/data/_adjustments.pyx']), | ||
]) | ||
def __setitem__(self, key, value): | ||
if key == 'build_ext': | ||
raise AssertionError("build_ext overridden!") | ||
super(LazyBuildExtCommandClass, self).__setitem__(key, value) | ||
|
||
def __getitem__(self, key): | ||
if key != 'build_ext': | ||
return super(LazyBuildExtCommandClass, self).__getitem__(key) | ||
|
||
from Cython.Distutils import build_ext as cython_build_ext | ||
|
||
class build_ext(cython_build_ext): | ||
""" | ||
Custom build_ext command that lazily adds numpy's include_dir to | ||
extensions. | ||
""" | ||
def build_extensions(self): | ||
""" | ||
Lazily append numpy's include directory to Extension includes. | ||
This is done here rather than at module scope because setup.py | ||
may be run before numpy has been installed, in which case | ||
importing numpy and calling `numpy.get_include()` will fail. | ||
""" | ||
numpy_incl = resource_filename('numpy', 'core/include') | ||
for ext in self.extensions: | ||
ext.include_dirs.append(numpy_incl) | ||
|
||
# This explicitly calls the superclass method rather than the | ||
# usual super() invocation because distutils' build_class, of | ||
# which Cython's build_ext is a subclass, is an old-style class | ||
# in Python 2, which doesn't support `super`. | ||
cython_build_ext.build_extensions(self) | ||
return build_ext | ||
|
||
|
||
ext_modules = [ | ||
Extension('zipline.assets._assets', ['zipline/assets/_assets.pyx']), | ||
Extension('zipline.lib.adjustment', ['zipline/lib/adjustment.pyx']), | ||
Extension( | ||
'zipline.lib._float64window', ['zipline/lib/_float64window.pyx'] | ||
), | ||
Extension('zipline.lib._int64window', ['zipline/lib/_int64window.pyx']), | ||
Extension('zipline.lib._uint8window', ['zipline/lib/_uint8window.pyx']), | ||
Extension('zipline.lib.rank', ['zipline/lib/rank.pyx']), | ||
Extension('zipline.data._equities', ['zipline/data/_equities.pyx']), | ||
Extension('zipline.data._adjustments', ['zipline/data/_adjustments.pyx']), | ||
] | ||
|
||
|
||
STR_TO_CMP = { | ||
|
@@ -116,9 +139,8 @@ def _filter_requirements(lines_iter): | |
yield requirement | ||
|
||
|
||
REQ_UPPER_BOUNDS = { | ||
'numpy': '<1.10', | ||
} | ||
# We don't currently have any known upper bounds. | ||
REQ_UPPER_BOUNDS = {} | ||
|
||
|
||
def _with_bounds(req): | ||
|
@@ -183,11 +205,12 @@ def extras_requires(conda_format=False): | |
} | ||
|
||
|
||
def module_requirements(requirements_path, module_names): | ||
def module_requirements(requirements_path, module_names, strict_bounds): | ||
module_names = set(module_names) | ||
found = set() | ||
module_lines = [] | ||
for line in read_requirements(requirements_path, strict_bounds=True): | ||
for line in read_requirements(requirements_path, | ||
strict_bounds=strict_bounds): | ||
match = REQ_PATTERN.match(line) | ||
if match is None: | ||
raise AssertionError("Could not parse requirement: '%s'" % line) | ||
|
@@ -203,38 +226,12 @@ def module_requirements(requirements_path, module_names): | |
) | ||
return module_lines | ||
|
||
|
||
def pre_setup(): | ||
if not set(sys.argv) & {'install', 'develop', 'egg_info', 'bdist_wheel'}: | ||
return | ||
|
||
try: | ||
import pip | ||
if StrictVersion(pip.__version__) < StrictVersion('7.1.0'): | ||
raise AssertionError( | ||
"Zipline installation requires pip>=7.1.0, but your pip " | ||
"version is {version}. \n" | ||
"You can upgrade your pip with " | ||
"'pip install --upgrade pip'.".format( | ||
version=pip.__version__, | ||
) | ||
) | ||
except ImportError: | ||
raise AssertionError("Zipline installation requires pip") | ||
|
||
required = ('Cython', 'numpy') | ||
for line in module_requirements('etc/requirements.txt', required): | ||
pip.main(['install', line]) | ||
|
||
|
||
pre_setup() | ||
|
||
conda_build = os.path.basename(sys.argv[0]) == 'conda-build' | ||
|
||
setup( | ||
name='zipline', | ||
version=versioneer.get_version(), | ||
cmdclass=versioneer.get_cmdclass(), | ||
cmdclass=LazyBuildExtCommandClass(versioneer.get_cmdclass()), | ||
description='A backtester for financial algorithms.', | ||
author='Quantopian Inc.', | ||
author_email='[email protected]', | ||
|
@@ -258,5 +255,10 @@ def pre_setup(): | |
], | ||
install_requires=install_requires(conda_format=conda_build), | ||
extras_require=extras_requires(conda_format=conda_build), | ||
setup_requires=module_requirements( | ||
'etc/requirements.txt', | ||
('Cython', 'numpy'), | ||
strict_bounds=False, | ||
), | ||
url="http://zipline.io", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.