quantstats icon indicating copy to clipboard operation
quantstats copied to clipboard

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

Open Barkan97 opened this issue 1 year ago • 6 comments

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 !!!

Barkan97 avatar Nov 17 '24 06:11 Barkan97

https://github.com/ranaroussi/quantstats/issues/377#issuecomment-2481024685

devanshu125 avatar Nov 17 '24 08:11 devanshu125

Tks bro, i got it !!!

Barkan97 avatar Nov 17 '24 10:11 Barkan97

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 avatar Dec 15 '24 13:12 caihua

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

caihua avatar Dec 15 '24 13:12 caihua

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

BambooOwl avatar Mar 21 '25 06:03 BambooOwl

I got the error only when I used quantstats.reports in jupyter notebook. So, with direct python scripts it works fine.

IamRam3 avatar May 05 '25 03:05 IamRam3

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.

ranaroussi avatar Jul 18 '25 14:07 ranaroussi