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

UnsupportedFunctionCall: numpy operations are not valid with resample. Use .resample(...).sum() instead #381

Open
Barkan97 opened this issue Nov 17, 2024 · 4 comments

Comments

@Barkan97
Copy link

I ran the simple code below and got an error:
qs.reports.full(returns=equity_return, benchmark=benchmark_return, output='report.html', title='Strategy')
(with equity_return and benchmark_return being Series and timeframe M30)
and I get the following error:

Passing additional kwargs to DatetimeIndexResampler.sum has no impact on the result and is deprecated. This will raise a TypeError in a future version of pandas.


UnsupportedFunctionCall Traceback (most recent call last)
in <cell line: 4>()
2 benchmark_return = backtest.data['Close'].pct_change().fillna(0).resample('D').sum()
3 #qs.reports.html(equity_return, benchmark_return, output='report.html')
----> 4 qs.reports.full(returns=equity_return,
5 benchmark=benchmark_return,
6 output='report.html',

5 frames
/usr/local/lib/python3.10/dist-packages/pandas/compat/numpy/function.py in validate_resampler_func(method, args, kwargs)
374 if len(args) + len(kwargs) > 0:
375 if method in RESAMPLER_NUMPY_OPS:
--> 376 raise UnsupportedFunctionCall(
377 "numpy operations are not valid with resample. "
378 f"Use .resample(...).{method}() instead"

UnsupportedFunctionCall: numpy operations are not valid with resample. Use .resample(...).sum() instead

Please guide me how to fix it, thank you !!!

@devanshu125
Copy link

#377 (comment)

@Barkan97
Copy link
Author

Tks bro, i got it !!!

@caihua
Copy link

caihua commented Dec 15, 2024

It has been a long time,
the first time I used it,
I encountered such a problem,
so far have not run through helloworld

@caihua
Copy link

caihua commented Dec 15, 2024

I downloaded the library code, and then based on
https://github.com/ranaroussi/quantstats/pull/375/files
https://github.com/bbalouki/quantstats/blob/bbs-dev/quantstats/_plotting/core.py
Line 292

  if resample:
       returns = returns.resample(resample).last() if compound else returns.resample(resample).sum()
       if isinstance(benchmark, _pd.Series):
           benchmark = benchmark.resample(resample).last() if compound else benchmark.resample(resample).sum()
           

Edit,
Then run it in your local library directory

pip install -e.

Then it worked

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