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

plot_timeseries does not handle types properly in Python 3.12 #61

Open
SergeyHein opened this issue Oct 3, 2024 · 2 comments
Open

plot_timeseries does not handle types properly in Python 3.12 #61

SergeyHein opened this issue Oct 3, 2024 · 2 comments

Comments

@SergeyHein
Copy link

Setup

  • quantstats_lumi 0.3.3
  • pandas 2.2.3
  • python 3.12
  • OS WSL / Ubuntu-24.04

Error

I'm receiving error when calling qs.reports.full

/******************-s8VZZPBo-py3.12/lib/python3.12/site-packages/quantstats_lumi/_plotting/core.py in ?(returns, benchmark, title, compound, cumulative, fill, returns_label, hline, hlw, hlcolor, hllabel, percent, match_volatility, log_scale, resample, lw, figsize, ylabel, grayscale, fontname, subtitle, savefig, show)
    357     # Set y-axis limits to avoid blank space at the bottom and top
    358     min_val = returns.min()
    359     max_val = returns.max()
    360     if benchmark is not None:
--> 361         min_val = min(min_val, benchmark.min())
    362         max_val = max(max_val, benchmark.max())
    363     ax.set_ylim(bottom=min_val, top=max_val)
    364 

/******************-s8VZZPBo-py3.12/lib/python3.12/site-packages/pandas/core/generic.py in ?(self)
   1575     @final
   1576     def __nonzero__(self) -> NoReturn:
-> 1577         raise ValueError(
   1578             f"The truth value of a {type(self).__name__} is ambiguous. "
   1579             "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
   1580         )

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Root cause

returns.min() is a Series whereas benchmark.min() is a float

Proposed solution

    # Set y-axis limits to avoid blank space at the bottom and top
    min_val = returns.min()
    max_val = returns.max()
    if isinstance(returns, _pd.DataFrame):
        min_val = min_val.iloc[0]
        max_val = max_val.iloc[0]
    if benchmark is not None:
        min_val = min(min_val, benchmark.min())
        max_val = max(max_val, benchmark.max())
@grzesir
Copy link
Contributor

grzesir commented Oct 3, 2024 via email

@SergeyHein
Copy link
Author

@grzesir here you go #62

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

2 participants