Skip to content

Commit

Permalink
Backport PR pandas-dev#55327: COMPAT: Fix warning with numba >= 0.58.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lithomas1 authored and meeseeksmachine committed Jan 11, 2024
1 parent 59c0a2d commit 8e4e248
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ Other
- 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`)
- Bug in the error message when assigning an empty :class:`DataFrame` to a column (:issue:`55956`)
- Bug when time-like strings were being cast to :class:`ArrowDtype` with ``pyarrow.time64`` type (:issue:`56463`)
- 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`)

.. ---------------------------------------------------------------------------
.. _whatsnew_220.contributors:
Expand Down
9 changes: 9 additions & 0 deletions pandas/core/util/numba_.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Common utilities for Numba operations"""
from __future__ import annotations

import types
from typing import (
TYPE_CHECKING,
Callable,
)

import numpy as np

from pandas.compat._optional import import_optional_dependency
from pandas.errors import NumbaUtilError

Expand Down Expand Up @@ -83,6 +86,12 @@ def jit_user_function(func: Callable) -> Callable:
if numba.extending.is_jitted(func):
# Don't jit a user passed jitted function
numba_func = func
elif getattr(np, func.__name__, False) is func or isinstance(
func, types.BuiltinFunctionType
):
# Not necessary to jit builtins or np functions
# This will mess up register_jitable
numba_func = func
else:
numba_func = numba.extending.register_jitable(func)

Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/window/test_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,10 @@ def test_table_method_ewm(self, data, method, axis, nogil, parallel, nopython):
engine_kwargs=engine_kwargs, engine="numba"
)
tm.assert_frame_equal(result, expected)


@td.skip_if_no("numba")
def test_npfunc_no_warnings():
df = DataFrame({"col1": [1, 2, 3, 4, 5]})
with tm.assert_produces_warning(False):
df.col1.rolling(2).apply(np.prod, raw=True, engine="numba")

0 comments on commit 8e4e248

Please sign in to comment.