Zipline & Pyfolio in M1 mac big sir 11.5.2

Hi,
After I updated Mac OS Big Sir to 11.5.2 on my MacBook Air (M1 2021), I’m not able to import zipline and pyfolio.
Below is error message. I can’t understand if this error rerates to OS update.

> Python 3.8.10 | packaged by conda-forge | (default, May 10 2021, 22:58:09) 
> [Clang 11.1.0 ] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import pyfolio
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/Users/pm/opt/miniconda3/envs/ml4t/lib/python3.8/site-packages/pyfolio/__init__.py", line 1, in <module>
>     from . import utils
>   File "/Users/pm/opt/miniconda3/envs/ml4t/lib/python3.8/site-packages/pyfolio/utils.py", line 26, in <module>
>     from . import pos
>   File "/Users/pm/opt/miniconda3/envs/ml4t/lib/python3.8/site-packages/pyfolio/pos.py", line 20, in <module>
>     from zipline.assets import Equity, Future
>   File "/Users/pm/opt/miniconda3/envs/ml4t/lib/python3.8/site-packages/zipline/__init__.py", line 21, in <module>
>     from trading_calendars import get_calendar
>   File "/Users/pm/opt/miniconda3/envs/ml4t/lib/python3.8/site-packages/trading_calendars/__init__.py", line 16, in <module>
>     from .trading_calendar import TradingCalendar
>   File "/Users/pm/opt/miniconda3/envs/ml4t/lib/python3.8/site-packages/trading_calendars/trading_calendar.py", line 33, in <module>
>     from .calendar_helpers import (
>   File "/Users/pm/opt/miniconda3/envs/ml4t/lib/python3.8/site-packages/trading_calendars/calendar_helpers.py", line 6, in <module>
>     NP_NAT = np.array([pd.NaT], dtype=np.int64)[0]
> TypeError: int() argument must be a string, a bytes-like object or a number, not 'NaTType'
> >>> exit()

Hello,

I’m not a Mac or conda user but I did previously experience this issue when importing zipline. Which version of pandas are you using? What fixed it for me was downgrading pandas to version 1.2.4

Alternatively you could try changing the offending line in calendar_helpers.py
from
NP_NAT = np.array([pd.NaT], dtype=np.int64)[0]
to
NP_NAT = pd.NaT.value
I did not try this myself but it is discussed in this thread regarding pandas 1.3.0 related errors;

1 Like

Hi joepython,
Thank you for your advise.
After I downgrade my pandas version to 1.2.4, both zipline and pyfolio works.

That’s right, the latest version limits pandas<1.3 for this reason. We are actively looking to transition to exchange_calendars for a longer-term solution.

1 Like