Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error importing zipline (trading calendars) #29

Closed
Tvix22 opened this issue Jul 5, 2021 · 12 comments
Closed

Error importing zipline (trading calendars) #29

Tvix22 opened this issue Jul 5, 2021 · 12 comments

Comments

@Tvix22
Copy link

Tvix22 commented Jul 5, 2021

Dear Zipline Maintainers,

Before I tell you about my issue, let me describe my environment:

Environment

  • Operating System: (Windows Version or $ uname --all) Ubuntu
  • Python Version: $ python --version : Python 3.9.1
  • Python Bitness: $ python -c 'import math, sys;print(int(math.log(sys.maxsize + 1, 2) + 1))'
  • How did you install Zipline: (pip, conda, or other (please explain)) pip install zipline-reloeaded
  • Python packages: $ pip freeze or $ conda list
  • packages in environment at /home/jcx/miniconda3:

Name Version Build Channel

_libgcc_mutex 0.1 main
alembic 1.6.5 pypi_0 pypi
anyio 3.2.1 py39hf3d152e_0 conda-forge
argon2-cffi 20.1.0 py39hbd71b63_2 conda-forge
async_generator 1.10 py_0 conda-forge
attrs 21.2.0 pyhd8ed1ab_0 conda-forge
babel 2.9.1 pyh44b312d_0 conda-forge
backcall 0.2.0 pyh9f0ad1d_0 conda-forge
backports 1.0 py_2 conda-forge
backports.functools_lru_cache 1.6.4 pyhd8ed1ab_0 conda-forge
bcolz-zipline 1.2.3.post2 pypi_0 pypi
bleach 3.3.0 pyh44b312d_0 conda-forge
bottleneck 1.3.2 pypi_0 pypi
brotlipy 0.7.0 py39h27cfd23_1003
ca-certificates 2021.5.30 ha878542_0 conda-forge
certifi 2021.5.30 py39hf3d152e_0 conda-forge
cffi 1.14.4 py39h261ae71_0
chardet 3.0.4 py39h06a4308_1003
click 8.0.1 pypi_0 pypi
conda 4.10.3 py39hf3d152e_0 conda-forge
conda-package-handling 1.7.2 py39h27cfd23_1
cryptography 3.3.1 py39h3c74f83_0
decorator 4.4.2 pypi_0 pypi
defusedxml 0.7.1 pyhd8ed1ab_0 conda-forge
empyrical-reloaded 0.5.7 pypi_0 pypi
entrypoints 0.3 pyhd8ed1ab_1003 conda-forge
greenlet 1.1.0 pypi_0 pypi
h5py 3.3.0 pypi_0 pypi
idna 2.10 py_0
importlib-metadata 4.6.0 py39hf3d152e_0 conda-forge
intervaltree 3.1.0 pypi_0 pypi
ipykernel 5.5.5 py39hef51801_0 conda-forge
ipython 7.25.0 py39hef51801_1 conda-forge
ipython_genutils 0.2.0 py_1 conda-forge
iso3166 1.0.1 pypi_0 pypi
iso4217 1.6.20180829 pypi_0 pypi
jedi 0.18.0 py39hf3d152e_2 conda-forge
jinja2 2.11.3 pyh44b312d_0 conda-forge
json5 0.9.5 pyh9f0ad1d_0 conda-forge
jsonschema 3.2.0 pyhd8ed1ab_3 conda-forge
jupyter_client 6.1.12 pyhd8ed1ab_0 conda-forge
jupyter_core 4.7.1 py39hf3d152e_0 conda-forge
jupyter_server 1.9.0 pyhd8ed1ab_0 conda-forge
jupyterlab 3.0.16 pyhd8ed1ab_0 conda-forge
jupyterlab_pygments 0.1.2 pyh9f0ad1d_0 conda-forge
jupyterlab_server 2.6.0 pyhd8ed1ab_0 conda-forge
ld_impl_linux-64 2.33.1 h53a641e_7
libedit 3.1.20191231 h14c3975_1
libffi 3.3 he6710b0_2
libgcc-ng 9.1.0 hdf63c60_0
libsodium 1.0.18 h36c2ea0_1 conda-forge
libstdcxx-ng 9.1.0 hdf63c60_0
logbook 1.5.3 pypi_0 pypi
lru-dict 1.1.7 pypi_0 pypi
lxml 4.6.3 pypi_0 pypi
mako 1.1.4 pypi_0 pypi
markupsafe 1.1.1 py39h38d8fee_2 conda-forge
matplotlib-inline 0.1.2 pyhd8ed1ab_2 conda-forge
mistune 0.8.4 py39hbd71b63_1002 conda-forge
multipledispatch 0.6.0 pypi_0 pypi
multitasking 0.0.9 pypi_0 pypi
nbclassic 0.3.1 pyhd8ed1ab_1 conda-forge
nbclient 0.5.3 pyhd8ed1ab_0 conda-forge
nbconvert 6.1.0 py39hf3d152e_0 conda-forge
nbformat 5.1.3 pyhd8ed1ab_0 conda-forge
ncurses 6.2 he6710b0_1
nest-asyncio 1.5.1 pyhd8ed1ab_0 conda-forge
networkx 2.5.1 pypi_0 pypi
notebook 6.4.0 pyha770c72_0 conda-forge
numexpr 2.7.3 pypi_0 pypi
numpy 1.21.0 pypi_0 pypi
openssl 1.1.1k h27cfd23_0
packaging 21.0 pyhd8ed1ab_0 conda-forge
pandas 1.3.0 pypi_0 pypi
pandas-datareader 0.9.0 pypi_0 pypi
pandoc 2.14.0.3 h7f98852_0 conda-forge
pandocfilters 1.4.2 py_1 conda-forge
parso 0.8.2 pyhd8ed1ab_0 conda-forge
patsy 0.5.1 pypi_0 pypi
pexpect 4.8.0 pyh9f0ad1d_2 conda-forge
pickleshare 0.7.5 py_1003 conda-forge
pip 20.3.1 py39h06a4308_0
prometheus_client 0.11.0 pyhd8ed1ab_0 conda-forge
prompt-toolkit 3.0.19 pyha770c72_0 conda-forge
ptyprocess 0.7.0 pyhd3deb0d_0 conda-forge
pycosat 0.6.3 py39h27cfd23_0
pycparser 2.20 py_2
pygments 2.9.0 pyhd8ed1ab_0 conda-forge
pyopenssl 20.0.0 pyhd3eb1b0_1
pyparsing 2.4.7 pyh9f0ad1d_0 conda-forge
pyrsistent 0.17.3 py39hbd71b63_1 conda-forge
pysocks 1.7.1 py39h06a4308_0
python 3.9.1 hdb3f193_2
python-dateutil 2.8.1 py_0 conda-forge
python-editor 1.0.4 pypi_0 pypi
python-interface 1.6.1 pypi_0 pypi
python_abi 3.9 2_cp39 conda-forge
pytz 2021.1 pyhd8ed1ab_0 conda-forge
pyzmq 19.0.2 py39hb69f2a1_2 conda-forge
readline 8.0 h7b6447c_0
requests 2.25.0 pyhd3eb1b0_0
requests-unixsocket 0.2.0 py_0 conda-forge
ruamel_yaml 0.15.80 py39h27cfd23_0
scipy 1.7.0 pypi_0 pypi
send2trash 1.7.1 pyhd8ed1ab_0 conda-forge
setuptools 51.0.0 py39h06a4308_2
six 1.15.0 py39h06a4308_0
sniffio 1.2.0 py39hf3d152e_1 conda-forge
sortedcontainers 2.4.0 pypi_0 pypi
sqlalchemy 1.4.20 pypi_0 pypi
sqlite 3.33.0 h62c20be_0
statsmodels 0.12.2 pypi_0 pypi
ta-lib 0.4.20 pypi_0 pypi
terminado 0.10.1 py39hf3d152e_0 conda-forge
testpath 0.5.0 pyhd8ed1ab_0 conda-forge
tk 8.6.10 hbc83047_0
toolz 0.11.1 pypi_0 pypi
tornado 6.1 py39hbd71b63_0 conda-forge
tqdm 4.54.1 pyhd3eb1b0_0
trading-calendars 2.1.1 pypi_0 pypi
traitlets 5.0.5 py_0 conda-forge
tzdata 2020d h14c3975_0
urllib3 1.25.11 py_0
wcwidth 0.2.5 pyh9f0ad1d_2 conda-forge
webencodings 0.5.1 py_1 conda-forge
websocket-client 0.57.0 py39hf3d152e_4 conda-forge
wheel 0.36.1 pyhd3eb1b0_0
xz 5.2.5 h7b6447c_0
yaml 0.2.5 h7b6447c_0
yfinance 0.1.60 pypi_0 pypi
zeromq 4.3.4 h2531618_0
zipline-reloaded 2.0.0.post1 pypi_0 pypi
zipp 3.5.0 pyhd8ed1ab_0 conda-forge
zlib 1.2.11 h7b6447c_3

Now that you know a little about me, let me tell you about the issue I am
having:

Description of Issue

When i use import zipline a recive an error i cant fix

  • What did you expect to happen?
    just import zipline
  • What happened instead?

TypeError Traceback (most recent call last)
in
----> 1 import zipline

~/miniconda3/lib/python3.9/site-packages/zipline/init.py in
19 # This is not a place to dump arbitrary classes/modules for convenience,
20 # it is a place to expose the public interfaces.
---> 21 from trading_calendars import get_calendar
22
23 from . import data

~/miniconda3/lib/python3.9/site-packages/trading_calendars/init.py in
14 # limitations under the License.
15
---> 16 from .trading_calendar import TradingCalendar
17 from .calendar_utils import (
18 clear_calendars,

~/miniconda3/lib/python3.9/site-packages/trading_calendars/trading_calendar.py in
31 import toolz
32
---> 33 from .calendar_helpers import (
34 NP_NAT,
35 compute_all_minutes,

~/miniconda3/lib/python3.9/site-packages/trading_calendars/calendar_helpers.py in
4 NANOSECONDS_PER_MINUTE = int(6e10)
5
----> 6 NP_NAT = np.array([pd.NaT], dtype=np.int64)[0]
7
8

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NaTType'

Here is how you can reproduce this issue on your machine:

Reproduction Steps

  1. create conda env
  2. pip install zipline-reloaded
  3. from jupyterlab import zipline
    ...

What steps have you taken to resolve this already?

...

Anything else?

...

Sincerely,

JCX

@Phali
Copy link

Phali commented Jul 5, 2021

I can reproduce this error in Windows 10 and a clean Python 3.7 environment

@MihailSalnikov
Copy link

MihailSalnikov commented Jul 6, 2021

Same problem on Ubuntu, Conda, Python 3.9

@MihailSalnikov
Copy link

Well, as I can understand, the problem in https://github.com/quantopian/trading_calendars/blob/master/trading_calendars/calendar_helpers.py#L6

Numpy just can't cast NaT to int64, and that looks ok. If you patch your tradinc_calendar like that, it will work (in my case)

NP_NAT = np.array([pd.NaT])[0]

Plus this PR please quantopian/trading_calendars#225

But maybe you will be faced with another problem:
ImportError: cannot import name 'gcd' from 'fractions' (/home/ms/miniconda3/envs/autotrade_env/lib/python3.9/fractions.py)
It's cause I use Python 3.9 and networkx too old. Update networkx to 2.5 and it will work.

@RiseT
Copy link

RiseT commented Jul 8, 2021

For what it's worth, there's maintained fork here that, among other things, seems to fix that issue:

https://github.com/gerrymanoim/exchange_calendars

@MBounouar
Copy link

imposing a lower on pandas version <=1.2.5 should fix the error

@RichardDale
Copy link

RichardDale commented Jul 30, 2021

Stefan, I think it's worth converting Zipline Reloaded to use @gerrymanoim 's exchange calendars.

(Note that Gerry was previous a Quantopian staffer, and now at Two Sigma)

@MBounouar
Copy link

@RichardDale
The issue is that exchange_calendars from gerrymanoim changed the opening and closing times definitions (which zipline relies upon) from t+1min to t. Someone would need to grab the baton there and look how hard it would be to convert zipline to to that change in opening/closing time definitions. I suspect the "easiest" would be to write some kind of wrapper to overwrite the calendar times, but maybe it would be more beneficial in the long term to change the logic there.

@jimmythekid
Copy link

Any update on this issue?

@MeerKatDev
Copy link

still there

@RichardDale
Copy link

RichardDale commented Aug 29, 2021

A temporary workaround is to restrict to Pandas to v1.2.5 instead of v1.3+

I've documented a working environment here that we use as part of Norgate's Zipline integration showing the exact command lines used on a Conda environment on Windows:
https://pypi.org/project/zipline-norgatedata/

Try this workaround and let us know if it works.

Cheers,
Richard.

@stefan-jansen
Copy link
Owner

Sorry for the delay, will take a look at this in the coming days.

@stefan-jansen
Copy link
Owner

Temporarily addressed by #47 that imposes pandas<1.3.0. We will work on the root cause and lift the pandas version constraint asap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants