Tag Archives: pyfolio

Debug | AttributeError: ‘numpy.int64‘ object has no attribute ‘to_pydatetime‘

reason

When using pyfolio , we encountered the following errors:

/usr/local/lib/python3.7/dist-packages/pyfolio/ timeseries.py in gen_ drawdown_ table(returns, top)
1006 recovery,
1007 freq=‘B’))
-> 1008 df_ drawdowns.loc [i, ‘Peak date’] = ( peak.to_ pydatetime()

AttributeError: ‘ numpy.int64 ’ object has no attribute ‘to_ pydatetime’

analysis

Confused, is very confused, after all, the transfer of a problem is also very uncomfortable.
search online, pyfoliogithub issues also has many people make complaints about this problem, such as #520, #652, #653, but more people are same error, no solution. 😦

Solution

Many solutions have been found on the Internet. They have tried one by one. Only the last one works well. Everyone can try it

s1 (Failed)

The /usr/local/lib/python3.7/dist-packages/pyfolio/ timeseries.py 893 line changed to

valley = underwater.index[np.argmin(underwater)] # end of the period

It’s no use, continue to change:

s2 (Failed)

The *. To_ Pydatetime() change to this

pd.to_datetime(peak)
pd.to_datetime(valley
pd.to_datetime(recovery)

Failure, and then repeatedly change those lines of code in the reference websites, mainly for the function that reported the error and def get_ max_ drawdown_ Underwater (underwater):
the code in
failed. It’s better to find a solution without changing the code:

sn (Success)

If we install it in PIP install pyfolio , then we uninstall and install it in GIT. Maybe it’s the latest version or something. In the end, this is the solution:

!pip uninstall pyfolio  # uninstall
!pip install git+https://github.com/quantopian/pyfolio # reinstall

After unloading, restart the code, or del pyfolio Import pyfolio , it is recommended to restart
and then run it again ~
finally, it’s out of the question: