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

AttributeError: 'numpy.int64' object has no attribute 'to_pydatetime' #710

Open
Jiujiuwhoami opened this issue Jan 4, 2024 · 2 comments

Comments

@Jiujiuwhoami
Copy link

Problem Description

Please provide a minimal, self-contained, and reproducible example:

import pandas as pd
import numpy as np
import pyfolio as pf

np.random.seed(42)
dates = pd.date_range('2022-01-01', periods=100)

returns_data = np.random.randn(100) / 100  
returns = pd.DataFrame({'returns': returns_data}, index=dates)
returns.index = pd.to_datetime(returns.index)
print(returns)
pf.plot_drawdown_periods(returns)

Please provide the full traceback:

Traceback (most recent call last):
  File "D:\quant_ai\mm\backtrader\text.py", line 14, in <module>
    pf.plot_drawdown_periods(returns)
  File "D:\python\lib\site-packages\pyfolio\plotting.py", line 432, in plot_drawdown_periods
    df_drawdowns = timeseries.gen_drawdown_table(returns, top=top)
  File "D:\python\lib\site-packages\pyfolio\timeseries.py", line 1008, in gen_drawdown_table
    df_drawdowns.loc[i, 'Valley date'] = (valley.to_pydatetime()
AttributeError: 'numpy.int64' object has no attribute 'to_pydatetime'

Please provide any additional information below:

Versions

  • Pyfolio version: pip install pyfolio
  • Python version: python3
  • Pandas version: yes
  • Matplotlib version: yes
@LexieZhuang
Copy link

Same! Do you know how to fix it?

@aten2005
Copy link

aten2005 commented Jun 26, 2024

Here's something that worked for me

Pyfolio version: 0.9.2
Python version: 3.11.7
Pandas version: 1.5.3
Matplotlib version: 3.8.0

I had to change the following function in the site-packages/pyfolio/timeseries.py file, from the commented line to the uncommented one.

def get_max_drawdown_underwater(underwater):

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

Source: here

I would highly recommend you use the pyfolio-reloaded library instead as this project does not seem to be under active development

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

3 participants