Skip to content

Commit 5955ca6

Browse files
COMPAT: Fix warning with numba >= 0.58.0 (pandas-dev#55327)
* COMPAT: Fix warning with numba >= 0.58.0 * Update numba_.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add a test * skip if no numba * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update v2.2.0.rst --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 50a43b4 commit 5955ca6

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ Other
944944
- Bug in rendering a :class:`Series` with a :class:`MultiIndex` when one of the index level's names is 0 not having that name displayed (:issue:`55415`)
945945
- Bug in the error message when assigning an empty :class:`DataFrame` to a column (:issue:`55956`)
946946
- Bug when time-like strings were being cast to :class:`ArrowDtype` with ``pyarrow.time64`` type (:issue:`56463`)
947+
- Fixed a spurious deprecation warning from ``numba`` >= 0.58.0 when passing a numpy ufunc in :class:`pandas.core.window.Rolling.apply` with ``engine="numba"`` (:issue:`55247`)
947948

948949
.. ---------------------------------------------------------------------------
949950
.. _whatsnew_220.contributors:

pandas/core/util/numba_.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
"""Common utilities for Numba operations"""
22
from __future__ import annotations
33

4+
import types
45
from typing import (
56
TYPE_CHECKING,
67
Callable,
78
)
89

10+
import numpy as np
11+
912
from pandas.compat._optional import import_optional_dependency
1013
from pandas.errors import NumbaUtilError
1114

@@ -83,6 +86,12 @@ def jit_user_function(func: Callable) -> Callable:
8386
if numba.extending.is_jitted(func):
8487
# Don't jit a user passed jitted function
8588
numba_func = func
89+
elif getattr(np, func.__name__, False) is func or isinstance(
90+
func, types.BuiltinFunctionType
91+
):
92+
# Not necessary to jit builtins or np functions
93+
# This will mess up register_jitable
94+
numba_func = func
8695
else:
8796
numba_func = numba.extending.register_jitable(func)
8897

pandas/tests/window/test_numba.py

+7
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,10 @@ def test_table_method_ewm(self, data, method, axis, nogil, parallel, nopython):
446446
engine_kwargs=engine_kwargs, engine="numba"
447447
)
448448
tm.assert_frame_equal(result, expected)
449+
450+
451+
@td.skip_if_no("numba")
452+
def test_npfunc_no_warnings():
453+
df = DataFrame({"col1": [1, 2, 3, 4, 5]})
454+
with tm.assert_produces_warning(False):
455+
df.col1.rolling(2).apply(np.prod, raw=True, engine="numba")

0 commit comments

Comments
 (0)