Skip to content

Commit

Permalink
Feature/zipline3dev (#18)
Browse files Browse the repository at this point in the history
* pandas > 2.0 + * sqlalchemy > 2 migration
* numpy fixes
  • Loading branch information
MBounouar authored Jun 28, 2023
1 parent 344fd96 commit 2f64091
Show file tree
Hide file tree
Showing 28 changed files with 345 additions and 391 deletions.
130 changes: 72 additions & 58 deletions .devcontainer/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,86 +1,100 @@
alembic==1.8.1
alembic==1.11.1
appdirs==1.4.4
attrs==22.1.0
bcolz-zipline==1.2.6
black==22.10.0
Bottleneck==1.3.5
certifi==2022.9.24
beautifulsoup4==4.12.2
black==22.12.0
blosc2==2.2.4
Bottleneck==1.3.7
cachetools==5.3.1
certifi==2023.5.7
cffi==1.15.1
cfgv==3.3.1
charset-normalizer==2.1.1
click==8.0.4
contourpy==1.0.6
coverage==6.5.0
chardet==5.1.0
charset-normalizer==3.1.0
click==8.1.3
colorama==0.4.6
contourpy==1.0.7
coverage==7.2.7
cryptography==41.0.1
cycler==0.11.0
Cython==0.29.35
distlib==0.3.6
empyrical-reloaded==0.5.8
exchange-calendars==3.3
empyrical-reloaded==0.5.9
exchange-calendars==4.2.8
execnet==1.9.0
filelock==3.8.0
flake8==5.0.4
fonttools==4.38.0
greenlet==2.0.1
h5py==3.7.0
identify==2.5.9
filelock==3.12.2
flake8==6.0.0
fonttools==4.39.4
frozendict==2.3.8
greenlet==2.0.2
h5py==3.8.0
html5lib==1.1
identify==2.5.24
idna==3.4
iniconfig==1.1.1
iniconfig==2.0.0
intervaltree==3.1.0
iso3166==2.1.1
iso4217==1.11.20220401
kiwisolver==1.4.4
korean-lunar-calendar==0.3.1
lru-dict==1.1.8
lxml==4.9.1
lru-dict==1.2.0
lxml==4.9.2
Mako==1.2.4
MarkupSafe==2.1.1
matplotlib==3.6.2
MarkupSafe==2.1.3
matplotlib==3.7.1
mccabe==0.7.0
msgpack==1.0.5
multipledispatch==0.6.0
multitasking==0.0.11
mypy-extensions==0.4.3
networkx==2.8.8
nodeenv==1.7.0
mypy-extensions==1.0.0
ndindex==1.7
networkx==3.1
nodeenv==1.8.0
numexpr==2.8.4
numpy==1.23.5
packaging==21.3
pandas==1.5.1
numpy==1.25.0
packaging==23.1
pandas==2.0.2
pandas-datareader==0.10.0
parameterized==0.8.1
pathspec==0.10.2
parameterized==0.9.0
pathspec==0.11.1
patsy==0.5.3
Pillow==9.3.0
platformdirs==2.5.4
Pillow==9.5.0
platformdirs==3.5.3
pluggy==1.0.0
pre-commit==2.20.0
py==1.11.0
pycodestyle==2.9.1
pyflakes==2.5.0
pyluach==2.0.2
pre-commit==3.3.2
py-cpuinfo==9.0.0
pycodestyle==2.10.0
pycparser==2.21
pyflakes==3.0.1
pyluach==2.2.0
pyparsing==3.0.9
pytest==6.2.5
pytest-cov==4.0.0
pytest-rerunfailures==10.3
pyproject-api==1.5.2
pytest==7.4.0
pytest-cov==4.1.0
pytest-rerunfailures==11.1.2
pytest-timeout==2.1.0
pytest-xdist==3.0.2
pytest-xdist==3.3.1
python-dateutil==2.8.2
python-interface==1.6.1
pytz==2022.6
pytz==2023.3
PyYAML==6.0
requests==2.28.1
responses==0.22.0
scipy==1.9.3
requests==2.31.0
responses==0.23.1
scipy==1.11.0
six==1.16.0
sortedcontainers==2.4.0
SQLAlchemy==1.4.44
statsmodels==0.13.5
TA-Lib==0.4.25
tables==3.7.0
testfixtures==7.0.3
toml==0.10.2
tomli==2.0.1
soupsieve==2.4.1
SQLAlchemy==2.0.17
statsmodels==0.14.0
TA-Lib==0.4.26
tables==3.8.0
testfixtures==7.1.0
toolz==0.12.0
tox==3.27.1
trading-calendars==2.1.1
types-toml==0.10.8.1
urllib3==1.26.12
virtualenv==20.16.7
yfinance==0.1.87
tox==4.6.3
types-PyYAML==6.0.12.10
typing_extensions==4.6.3
tzdata==2023.3
urllib3==2.0.3
virtualenv==20.23.1
webencodings==0.5.1
yfinance==0.2.22
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ dependencies = [
'multipledispatch >=0.6.0',
'networkx >=2.0',
'numexpr >=2.6.1',
'numpy >=1.14.5, <1.24',
'pandas >=1.3, <1.6',
'numpy >=1.14.5',
'pandas >=2.0',
'patsy >=0.4.0',
'python-dateutil >=2.4.2',
'python-interface >=1.5.3',
'pytz >=2018.5',
'requests >=2.9.1',
'scipy >=0.17.1',
'six >=1.10.0',
'sqlalchemy >=1.0.8A, <2',
'sqlalchemy >=2',
'statsmodels >=0.6.1',
'ta-lib >=0.4.09',
'tables >=3.4.3',
Expand Down
8 changes: 3 additions & 5 deletions src/zipline/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from collections import namedtuple
from copy import copy
import warnings
from datetime import tzinfo, time
from datetime import tzinfo, time, timezone
import logging
import pytz
import pandas as pd
Expand Down Expand Up @@ -537,7 +537,6 @@ def _create_benchmark_source(self):
benchmark_asset = self.asset_finder.retrieve_asset(self.benchmark_sid)
benchmark_returns = None
else:

benchmark_asset = None
benchmark_returns = self.benchmark_returns
return BenchmarkSource(
Expand Down Expand Up @@ -644,7 +643,6 @@ def _create_daily_stats(self, perfs):
# warning.
for perf in perfs:
if "daily_perf" in perf:

perf["daily_perf"].update(perf["daily_perf"].pop("recorded_vars"))
perf["daily_perf"].update(perf["cumulative_risk_metrics"])
daily_perfs.append(perf["daily_perf"])
Expand Down Expand Up @@ -778,7 +776,7 @@ def fetch_csv(
post_func=None,
date_column="date",
date_format=None,
timezone=pytz.utc.zone,
timezone=str(timezone.utc),
symbol=None,
mask=True,
symbol_column=None,
Expand Down Expand Up @@ -1455,7 +1453,7 @@ def get_datetime(self, tz=None):
The current simulation datetime converted to ``tz``.
"""
dt = self.datetime
assert dt.tzinfo == pytz.utc, "Algorithm should have a utc datetime"
assert dt.tzinfo == timezone.utc, "Algorithm should have a utc datetime"
if tz is not None:
dt = dt.astimezone(tz)
return dt
Expand Down
12 changes: 7 additions & 5 deletions src/zipline/assets/asset_db_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ def downgrade(engine, desired_version):

# Check the version of the db at the engine
with engine.begin() as conn:
metadata = sa.MetaData(conn)
metadata.reflect()
version_info_table = metadata.tables["version_info"]
starting_version = sa.select((version_info_table.c.version,)).scalar()
metadata_obj = sa.MetaData()
metadata_obj.reflect(conn)
version_info_table = metadata_obj.tables["version_info"]
# starting_version = sa.select((version_info_table.c.version,)).scalar()
starting_version = conn.execute(
sa.select(version_info_table.c.version)
).scalar()

# Check for accidental upgrade
if starting_version < desired_version:
Expand Down Expand Up @@ -180,7 +183,6 @@ def _downgrade_v1(op):

# Execute batch op to allow column modification in SQLite
with op.batch_alter_table("futures_contracts") as batch_op:

# Rename 'multiplier'
batch_op.alter_column(
column_name="multiplier", new_column_name="contract_multiplier"
Expand Down
3 changes: 1 addition & 2 deletions src/zipline/assets/asset_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def check_version_info(conn, version_table, expected_version: int):
Parameters
----------
conn : sa.Connection
conn : Connection
The connection to use to perform the check.
version_table : sa.Table
The version table of the asset database
Expand All @@ -424,7 +424,6 @@ def check_version_info(conn, version_table, expected_version: int):
AssetDBVersionError
If the version is in the table and not equal to ASSET_DB_VERSION.
"""

# Read the version out of the table
version_from_table = conn.execute(sa.select(version_table.c.version)).scalar()

Expand Down
Loading

0 comments on commit 2f64091

Please sign in to comment.