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

Error in reports.full() comparing a pandas series to a scaler for plotting axis #55

Open
kennymcavoy opened this issue Aug 3, 2024 · 0 comments · May be fixed by #64
Open

Error in reports.full() comparing a pandas series to a scaler for plotting axis #55

kennymcavoy opened this issue Aug 3, 2024 · 0 comments · May be fixed by #64

Comments

@kennymcavoy
Copy link

kennymcavoy commented Aug 3, 2024

Code:

import pandas as pd
import numpy as np
import quantstats_lumi as qs

stock = qs.utils.download_returns('META')
qs.reports.full(stock, "SPY")

Error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../lib/python3.12/site-packages/pandas/core/generic.py", line 1577, in __nonzero__
    raise ValueError(
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Looks like the plots class turns returns series into a dataframe just before _plots.returns() which is passed to _core.plot_timeseries(). In this class there's a section to set the min and max value of returns for the plot sizes that uses returns.min()/max() and compares that to the benchmark, which throws the error as min()/max() of the dataframe returns a series indexed by the strategy.

code throwing the error:

    # Set y-axis limits to avoid blank space at the bottom and top
    min_val = returns.min() <- series indexed by strategy
    max_val = returns.max() <- series indexed by strategy
    if benchmark is not None:
        min_val = min(min_val, benchmark.min()) <- comparing series to scaler, source of error
        max_val = max(max_val, benchmark.max())
    ax.set_ylim(bottom=min_val, top=max_val)

Also, separate issue, after just doing a local fix for this (added extra min(): returns.min().min()/max(), this does break the reports.html() function) the plots appear and disappear immediately.

@AndreBBM AndreBBM linked a pull request Oct 30, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant