quantstats icon indicating copy to clipboard operation
quantstats copied to clipboard

UnsupportedFunctionCall

Open bbalouki opened this issue 1 year ago • 6 comments

qs.reports.full(returns, mode='full', benchmark=benchmark) File "C:\ProgramData\miniconda3\envs\bbsdev\lib\site-packages\quantstats\reports.py", line 628, in full plots( File "C:\ProgramData\miniconda3\envs\bbsdev\lib\site-packages\quantstats\reports.py", line 1346, in plots _plots.daily_returns( File "C:\ProgramData\miniconda3\envs\bbsdev\lib\site-packages\quantstats_plotting\wrappers.py", line 512, in daily_returns fig = _core.plot_timeseries( File "C:\ProgramData\miniconda3\envs\bbsdev\lib\site-packages\quantstats_plotting\core.py", line 294, in plot_timeseries returns = returns.last() if compound is True else returns.sum(axis=0) File "C:\ProgramData\miniconda3\envs\bbsdev\lib\site-packages\pandas\core\resample.py", line 1183, in sum nv.validate_resampler_func("sum", args, kwargs) File "C:\ProgramData\miniconda3\envs\bbsdev\lib\site-packages\pandas\compat\numpy\function.py", line 376, in validate_resampler_func raise UnsupportedFunctionCall( pandas.errors.UnsupportedFunctionCall: numpy operations are not valid with resample. Use .resample(...).sum() instead

bbalouki avatar Oct 27 '24 17:10 bbalouki

Same problem here...

julienwagener avatar Oct 29 '24 22:10 julienwagener

I also encountered the same issue, the code was working fine previously but suddenly gives below error when I try to create a html report. Not sure if it coincide with recent yahoodownloader update, but hopefully a solution can be found soon image

yaping19 avatar Oct 30 '24 01:10 yaping19

To fix the resampling issue in the quantstats library, locate the "core.py" file in the quantstats installation directory (usually found in your Python site-packages).

Around line 292, replace the existing code with the following:

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

I haven't tested the entire repo, but when I call full() it works. :)

KingTurbo avatar Nov 04 '24 16:11 KingTurbo

It was issued by brunch in "Issues" https://github.com/ranaroussi/quantstats/pull/375.

JomaDeveloper avatar Nov 06 '24 10:11 JomaDeveloper

Still there are some issues as below ../miniforge3/envs/fin12/lib/python3.12/site-packages/quantstats/_plotting/core.py:1016: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method. The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.

For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.

port["Weekly"].ffill(inplace=True) ../miniforge3/envs/fin12/lib/python3.12/site-packages/quantstats/_plotting/core.py:1019: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method. The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.

For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.

port["Monthly"].ffill(inplace=True) ../miniforge3/envs/fin12/lib/python3.12/site-packages/quantstats/_plotting/core.py:1022: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method. The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.

For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.

port["Quarterly"].ffill(inplace=True) ../miniforge3/envs/fin12/lib/python3.12/site-packages/quantstats/_plotting/core.py:1025: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method. The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.

For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.

port["Yearly"].ffill(inplace=True)

subinoy avatar Nov 07 '24 12:11 subinoy

code qs.reports.full(stock)

result

/usr/local/lib/python3.11/dist-packages/quantstats/_plotting/core.py:294: FutureWarning: 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.
  returns = returns.last() if compound is True else returns.sum(axis=0)
---------------------------------------------------------------------------
UnsupportedFunctionCall                   Traceback (most recent call last)
[<ipython-input-16-ebcea8f89bdb>](https://localhost:8080/#) in <cell line: 0>()
----> 1 qs.reports.full(stock)

5 frames
[/usr/local/lib/python3.11/dist-packages/pandas/compat/numpy/function.py](https://localhost:8080/#) 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

best regards

sugizo avatar May 17 '25 00:05 sugizo

Closing this issue as it's older than 2025 and has been specifically addressed in release 0.0.64. The UnsupportedFunctionCall errors have been resolved with the comprehensive pandas compatibility layer implementation.

ranaroussi avatar Jul 18 '25 14:07 ranaroussi