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

This issue has been created since 2022-09-21.

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

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

mroeschke wrote this answer on 2022-09-24

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

donghyyun wrote this answer on 2022-09-24

@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

More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-09-29
Star Count 35374
Watcher Count 1122
Fork Count 15034
Issue Count 3579

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Enabling drag select of objects 3 2022-02-26 2022-09-18
Altering the update velocity parameter 4 2021-01-16 2022-09-17
Container exit code 0 despite getting a non-0 exit code in logs 9 2021-01-20 2022-09-15
Conversion to execline-2.7.0.0 21 2021-01-14 2022-09-20
Publish FreeSpec and extensions to Opam 1 2019-03-02 2022-09-17
Reasons for Xkeysnail to not work under FreeBSD? 3 2021-01-03 2022-08-26
Redefinition of module 'CommonCrypto' 3 2021-08-23 2022-08-24
integration lsp-mode 2 2022-06-04 2022-08-15
Implement VCVT (between floating-point and fixed-point) instruction 2 2021-12-08 2022-09-04
Explicit example of problem with simplify involving hyperbolic trig functions 16 2022-01-24 2022-07-20
patternProperties not being displayed 1 2022-05-06 2022-08-22
DB/Locale/zhTW fix wrong zhTW for creature,quest_greeting,achievement_reward 2022.04 1 2022-05-05 2022-09-15
Proposal to work on a Alert Component 1 2021-04-18 2022-09-16
Bug: .editorconfig breaks TableOutputFormatterTest 4 2021-07-01 2022-07-27
ERROR: relation "migration_model" does not exist 20 2022-02-15 2022-09-26
What is the licence? 2 2019-03-14 2022-09-18
Error Starting Kubernetes 1 2022-02-02 2022-09-21
TypeError in Db\Reader\Decoder with bcmath extension 3 2021-03-24 2022-09-20
how can i choose frida server for ios 1 2022-04-19 2022-09-24
[Autoscaler] google-cloud-storage seems cannot read GOOGLE_APPLICATION_CREDENTIALS 3 2022-05-31 2022-09-19
Sending smtp with starttls 4 2022-09-13 2022-09-28
stdout metric collector 16 2021-08-30 2022-09-28
Add support for r6g and c6g instance types 2 2020-11-18 2022-09-24
Can not delete ACM completely alongside beta-private-cluster 2 2022-05-11 2022-09-16
Support both min_master_version and release_channel attributes 1 2022-05-13 2022-09-17
How to use cot command-line tool. 0 2021-12-02 2022-09-23
Update ts.jte settings when running with Java SE 17 to add --add-opens 3 2022-05-05 2022-09-06
Remove HttpUtils use in jsp 2 2022-05-05 2022-09-06
Cannot create community - no field for intro message 0 2022-07-28 2022-08-23
[Bug]: x265 missing acceleration on aarch64? 2 2022-07-23 2022-08-29
README outdated since the console script migration 0 2021-01-19 2022-09-17
I am unable to execute this code, it would be really helpful if you could take some time to help me 3 2021-12-18 2022-09-19
Update wasmer-emscripten to use the new Context API 1 2022-06-01 2022-09-28
Level Up! : The hint of step10 is not accurate 1 2021-11-04 2022-09-28
Maintain variant specific PIM attributes 2 2021-07-14 2022-09-17
Support any composer-type repository 8 2018-03-20 2022-09-22
Added CCC page 1 2021-01-01 2022-01-14
Weekly Digest (19 March, 2021 - 26 March, 2021) 0 2021-03-26 2022-09-15
Change locale at runtime 0 2021-12-17 2022-09-19
ERROR: usbmuxd is not running! on Android 0 2022-09-15 2022-09-26
script replace does not work with different arguments 3 2021-01-21 2022-09-08
stylesheet replace fails 2 2021-01-21 2022-09-08
The apoc.export.cypher.* procedures don't create relationships with start/end node without properties. 0 2022-05-13 2022-09-16
[virtualizer] Not enough DOM nodes created with large item height 0 2022-07-26 2022-08-16
Fix error in GCP integration module debug message 0 2021-09-24 2022-09-08
Feat: Add compression strategy 3 2021-08-13 2022-09-02
[bug]<v3.9.2>URIError 报错 1 2021-11-03 2022-09-21
Error in block 'battery': failed to load file /sys/class/power_supply/apple_mfi_fastcharge/status 2 2022-03-14 2022-09-02
Refactor ExecutionContext and related conf to support multi-tenancy configurations. 8 2022-02-18 2022-08-16
dump debugging docs feedback 0 2022-02-09 2022-09-26