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

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

Closed
playingwithpy opened this issue Aug 5, 2021 · 3 comments

Comments

@playingwithpy
Copy link

Dear Zipline Maintainers,

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

Environment

Pycharm 2021.2 CE

*Operating System == Linux 5.11.0-7620-generic x86_64 GNU/Linux
*Python Version == Python 3.7.11
*Python Bitness == 64
*Installed Via == pip install zipline-reloaded

  • Python packages:
    alembic==1.6.5
    alphalens==0.4.0
    backcall==0.2.0
    bcolz-zipline==1.2.3.post2
    Bottleneck==1.3.2
    cached-property==1.5.2
    certifi==2021.5.30
    charset-normalizer==2.0.4
    click==8.0.1
    cycler==0.10.0
    decorator==5.0.9
    empyrical==0.5.5
    empyrical-reloaded==0.5.7
    greenlet==1.1.0
    h5py==3.3.0
    idna==3.2
    importlib-metadata==4.6.3
    intervaltree==3.1.0
    ipython==7.26.0
    ipython-genutils==0.2.0
    iso3166==1.0.1
    iso4217==1.6.20180829
    jedi==0.18.0
    joblib==1.0.1
    kiwisolver==1.3.1
    Logbook==1.5.3
    lru-dict==1.1.7
    lxml==4.6.3
    Mako==1.1.4
    MarkupSafe==2.0.1
    matplotlib==3.4.2
    matplotlib-inline==0.1.2
    multipledispatch==0.6.0
    multitasking==0.0.9
    networkx==2.6.2
    numexpr==2.7.3
    numpy==1.21.1
    pandas==1.3.1
    pandas-datareader==0.10.0
    parso==0.8.2
    patsy==0.5.1
    pexpect==4.8.0
    pickleshare==0.7.5
    Pillow==8.3.1
    prompt-toolkit==3.0.19
    ptyprocess==0.7.0
    pyfolio==0.9.2
    Pygments==2.9.0
    pyparsing==2.4.7
    python-dateutil==2.8.2
    python-editor==1.0.4
    python-interface==1.6.1
    pytz==2021.1
    requests==2.26.0
    scikit-learn==0.24.2
    scipy==1.7.1
    seaborn==0.11.1
    six==1.16.0
    sortedcontainers==2.4.0
    SQLAlchemy==1.4.22
    statsmodels==0.12.2
    TA-Lib==0.4.21
    threadpoolctl==2.2.0
    toolz==0.11.1
    trading-calendars==2.1.1
    traitlets==5.0.5
    typing-extensions==3.10.0.0
    urllib3==1.26.6
    wcwidth==0.2.5
    yfinance==0.1.63
    zipline-reloaded==2.0.0.post1
    zipp==3.5.0

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

Description of Issue

When I go to import zipline, I get the error:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NaTType'

The above error occurs in the file '/venv/lib/python3.7/site-packages/trading_calendars/calendar_helpers.py'

The specific line of code causing the issue is:
NP_NAT = np.array([pd.NaT], dtype=np.int64)[0]

  • What did you expect to happen?
    zipline would be imported without issue.

  • What happened instead?
    The full trace:
    Traceback (most recent call last):
    File "/venv/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3441, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
    File "", line 1, in
    import zipline
    File "/pycharm-community-2021.2/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
    File "/venv/lib/python3.7/site-packages/zipline/init.py", line 21, in
    from trading_calendars import get_calendar
    File "/pycharm-community-2021.2/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
    File "/PycharmProjects/ziplineReloaded/venv/lib/python3.7/site-packages/trading_calendars/init.py", line 16, in
    from .trading_calendar import TradingCalendar
    File "/pycharm-community-2021.2/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
    File "/PycharmProjects/ziplineReloaded/venv/lib/python3.7/site-packages/trading_calendars/trading_calendar.py", line 33, in
    from .calendar_helpers import (
    File "/pycharm-community-2021.2/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
    File "/PycharmProjects/ziplineReloaded/venv/lib/python3.7/site-packages/trading_calendars/calendar_helpers.py", line 7, in
    NP_NAT = np.array([pd.NaT], dtype=np.int64)[0] # Original line from Classic Zipline.
    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. Compile python 3.7.11 from source after installing the dependencies outlined at https://zipline.ml4trading.io/install.html
  2. sudo make altinstall
  3. Create new project venv in Pycharm CE
  4. pip install zipline-reloaded as described at https://zipline.ml4trading.io/#installation
    ...

What steps have you taken to resolve this already?

  1. I searched online for info about NaT and how to convert this data type to int64 as per my limited understanding of what this line tries to do.

  2. I tried simply omitting "dtype=np.int64" from the line in question. This change allowed me to import zipline without problems.
    However it causes "RuntimeWarning: overflow encountered in long_scalars
    NANOSECONDS_PER_MINUTE," when attempting to ingest a custom data bundle. I can provide more info on this if needed.

  3. Tried pasting the full TypeError message into stackoverflow but I couldn't find a fix or similar issue thread.

...

Anything else?

NaT means "Not a Time Object" yes? Is the point of this line to simply create a blank time or datetime object as a place holder?
Thank you very much in advance for any assistance that can be shared.
...

Sincerely,
playingwithpy

@RiseT
Copy link

RiseT commented Aug 6, 2021

Duplicate of #29

@complexsum
Copy link

I was also stumbled upon this issue, it seem to be fixed after installing pandas version 1.1.5.

@stefan-jansen
Copy link
Owner

Duplicate of #29; temporarily addressed by #47. 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

4 participants