UnsupportedFunctionCall: numpy operations are not valid with resample. Use .resample(...).sum() instead
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)
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 !!!
https://github.com/ranaroussi/quantstats/issues/377#issuecomment-2481024685
Tks bro, i got it !!!
It has been a long time, the first time I used it, I encountered such a problem, so far have not run through helloworld
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
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
good stuff, thank you for the fix
I got the error only when I used quantstats.reports in jupyter notebook. So, with direct python scripts it works fine.
Closing this issue as it's older than 2025 and has been specifically addressed in release 0.0.64. The pandas resampling compatibility issues have been resolved with the comprehensive compatibility layer implementation.