Skip to content

ENH: Support Resampler.mean(engine="numba") #48675

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

Open
3 tasks done
donghyyun opened this issue Sep 21, 2022 · 2 comments
Open
3 tasks done

ENH: Support Resampler.mean(engine="numba") #48675

donghyyun opened this issue Sep 21, 2022 · 2 comments
Labels
Enhancement numba numba-accelerated operations Resample resample method

Comments

@donghyyun
Copy link
Contributor

donghyyun commented Sep 21, 2022

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd 

index = pd.date_range('1/1/2019', periods=12, freq='T')
series = pd.Series(range(12), index=index)

# Returns 'UnsupportedFunctionCall' error
series.resample("1T").mean(engine="numba")

Issue Description

Based on reference, I tried to apply numba engine to my code. However, faced an error as below

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

> UnsupportedFunctionCall Traceback (most recent call last) > Input In [15], in () > 4 series = pd.Series(range(12), index=index) > 6 # Returns 'UnsupportedFunctionCall' error > ----> 7 series.resample("1T").mean(engine="numba") > > File /opt/homebrew/Caskroom/miniforge/base/envs/onboarding/lib/python3.9/site-packages/pandas/core/resample.py:1100, in _add_downsample_kernel..f(self, numeric_only, *args, **kwargs) > 1097 def f( # type: ignore[misc] > 1098 self, numeric_only: bool | lib.NoDefault = lib.no_default, *args, **kwargs > 1099 ): > -> 1100 nv.validate_resampler_func(name, args, kwargs) > 1101 return self._downsample(name, numeric_only=numeric_only) > > File /opt/homebrew/Caskroom/miniforge/base/envs/onboarding/lib/python3.9/site-packages/pandas/compat/numpy/function.py:408, in validate_resampler_func(method, args, kwargs) > 406 if len(args) + len(kwargs) > 0: > 407 if method in RESAMPLER_NUMPY_OPS: > --> 408 raise UnsupportedFunctionCall( > 409 "numpy operations are not valid with resample. " > 410 f"Use .resample(...).{method}() instead" > 411 ) > 412 else: > 413 raise TypeError("too many arguments passed in") > > UnsupportedFunctionCall: numpy operations are not valid with resample. Use .resample(...).mean() instead

FYI: it works when run as below, but the output type is DataFrame with column name 'mean', not Series
series.resample("1T").agg(["mean"], engine="numba")

Expected Behavior

Same result as running series.resample("1T").mean() without an error
& Run through JIT compiled code from numba

Installed Versions

INSTALLED VERSIONS

commit : 87cfe4e
python : 3.9.13.final.0
python-bits : 64
OS : Darwin
OS-release : 21.4.0
Version : Darwin Kernel Version 21.4.0: Mon Feb 21 20:35:58 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 1.5.0
numpy : 1.22.4
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 65.3.0
pip : 22.2.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.3
numba : 0.55.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.0
snappy : None
sqlalchemy : 1.4.40
tables : None
tabulate : 0.8.10
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@donghyyun donghyyun added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 21, 2022
@donghyyun donghyyun changed the title BUG: Resampler.mean(engine="numba") results error BUG: Resampler.mean(engine="numba") results error Sep 22, 2022
@mroeschke mroeschke removed the Needs Triage Issue that has not been reviewed by a pandas team member label Sep 22, 2022
@mroeschke
Copy link
Member

Thanks for the report.

The numba engine hasn't be implemented for resample, just groupby and rolling so relabeling as an enhancement request.

Nonetheless, the error message is not entirely clear here

@mroeschke mroeschke changed the title BUG: Resampler.mean(engine="numba") results error ENH: Support Resampler.mean(engine="numba") Sep 22, 2022
@mroeschke mroeschke added Enhancement Resample resample method numba numba-accelerated operations and removed Bug labels Sep 22, 2022
@donghyyun
Copy link
Contributor Author

donghyyun commented Sep 23, 2022

@mroeschke Thank you for the reply.

If numba engine is not supported in resample, I think the documentation should be revised.

And sorry for the unclear error message. The full error message is:

UnsupportedFunctionCall Traceback (most recent call last)
Input In [15], in <cell line: 7>()
4 series = pd.Series(range(12), index=index)
6 # Returns 'UnsupportedFunctionCall' error
----> 7 series.resample("1T").mean(engine="numba")

File /opt/homebrew/Caskroom/miniforge/base/envs/onboarding/lib/python3.9/site-packages/pandas/core/resample.py:1100, in _add_downsample_kernel..f(self, numeric_only, *args, **kwargs)
1097 def f( # type: ignore[misc]
1098 self, numeric_only: bool | lib.NoDefault = lib.no_default, *args, **kwargs
1099 ):
-> 1100 nv.validate_resampler_func(name, args, kwargs)
1101 return self._downsample(name, numeric_only=numeric_only)

File /opt/homebrew/Caskroom/miniforge/base/envs/onboarding/lib/python3.9/site-packages/pandas/compat/numpy/function.py:408, in validate_resampler_func(method, args, kwargs)
406 if len(args) + len(kwargs) > 0:
407 if method in RESAMPLER_NUMPY_OPS:
--> 408 raise UnsupportedFunctionCall(
409 "numpy operations are not valid with resample. "
410 f"Use .resample(...).{method}() instead"
411 )
412 else:
413 raise TypeError("too many arguments passed in")

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement numba numba-accelerated operations Resample resample method
Projects
None yet
Development

No branches or pull requests

2 participants