From 9343ecab4c13eda927f138d9b5e469ddd2257699 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Fri, 29 Sep 2023 15:18:48 -0400 Subject: [PATCH 1/7] COMPAT: Fix warning with numba >= 0.58.0 --- doc/source/whatsnew/v2.2.0.rst | 1 + pandas/core/util/numba_.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index 6ddb1613076ac..4a85d534ddeba 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -252,6 +252,7 @@ Bug fixes - Bug in :class:`pandas.core.window.Rolling` where duplicate datetimelike indexes are treated as consecutive rather than equal with ``closed='left'`` and ``closed='neither'`` (:issue:`20712`) - Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`) - Bug in :meth:`pandas.read_excel` with a ODS file without cached formatted cell for float values (:issue:`55219`) +- 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`) Categorical ^^^^^^^^^^^ diff --git a/pandas/core/util/numba_.py b/pandas/core/util/numba_.py index b8d489179338b..f9bc6b68f193b 100644 --- a/pandas/core/util/numba_.py +++ b/pandas/core/util/numba_.py @@ -6,6 +6,8 @@ Callable, ) +import numpy as np + from pandas.compat._optional import import_optional_dependency from pandas.errors import NumbaUtilError @@ -79,10 +81,17 @@ def jit_user_function(func: Callable) -> Callable: import numba else: numba = import_optional_dependency("numba") + import types 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) From aa60545e542f6f55fae5265de25f89676b393599 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:45:43 -0400 Subject: [PATCH 2/7] Update numba_.py --- pandas/core/util/numba_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/util/numba_.py b/pandas/core/util/numba_.py index f9bc6b68f193b..d65db691f670b 100644 --- a/pandas/core/util/numba_.py +++ b/pandas/core/util/numba_.py @@ -7,6 +7,7 @@ ) import numpy as np +import types from pandas.compat._optional import import_optional_dependency from pandas.errors import NumbaUtilError @@ -81,7 +82,6 @@ def jit_user_function(func: Callable) -> Callable: import numba else: numba = import_optional_dependency("numba") - import types if numba.extending.is_jitted(func): # Don't jit a user passed jitted function From e6995b67b1c1d42a4556c1cee85753ccc60c663b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 19:39:14 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/core/util/numba_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/util/numba_.py b/pandas/core/util/numba_.py index d65db691f670b..4825c9fee24b1 100644 --- a/pandas/core/util/numba_.py +++ b/pandas/core/util/numba_.py @@ -1,13 +1,13 @@ """Common utilities for Numba operations""" from __future__ import annotations +import types from typing import ( TYPE_CHECKING, Callable, ) import numpy as np -import types from pandas.compat._optional import import_optional_dependency from pandas.errors import NumbaUtilError From 16a453de13e157a6a70c2fe95ea90fd26d5b948b Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Thu, 28 Dec 2023 15:48:45 -0800 Subject: [PATCH 4/7] add a test --- pandas/tests/window/test_numba.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/tests/window/test_numba.py b/pandas/tests/window/test_numba.py index b1cc7ec186f19..8f1da92eb32dd 100644 --- a/pandas/tests/window/test_numba.py +++ b/pandas/tests/window/test_numba.py @@ -446,3 +446,9 @@ def test_table_method_ewm(self, data, method, axis, nogil, parallel, nopython): engine_kwargs=engine_kwargs, engine="numba" ) tm.assert_frame_equal(result, expected) + + +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') From c8bb008dcb0ad7adc0d179e3cd6c06e09da6dcd3 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Fri, 29 Dec 2023 10:10:47 -0800 Subject: [PATCH 5/7] skip if no numba --- pandas/tests/window/test_numba.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/window/test_numba.py b/pandas/tests/window/test_numba.py index 8f1da92eb32dd..3e8e12cb402bb 100644 --- a/pandas/tests/window/test_numba.py +++ b/pandas/tests/window/test_numba.py @@ -448,6 +448,7 @@ def test_table_method_ewm(self, data, method, axis, nogil, parallel, nopython): 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): From df4f48ac2dfe5368da5f7f142ab4ab81bbe92186 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:16:34 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/tests/window/test_numba.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/window/test_numba.py b/pandas/tests/window/test_numba.py index 3e8e12cb402bb..139e1ff7f65fd 100644 --- a/pandas/tests/window/test_numba.py +++ b/pandas/tests/window/test_numba.py @@ -450,6 +450,6 @@ def test_table_method_ewm(self, data, method, axis, nogil, parallel, nopython): @td.skip_if_no("numba") def test_npfunc_no_warnings(): - df = DataFrame({'col1': [1, 2, 3, 4, 5]}) + 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') + df.col1.rolling(2).apply(np.prod, raw=True, engine="numba") From 860633b6474a31ca50efa98ced7f39fb83ea7b56 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Wed, 10 Jan 2024 14:39:53 -0800 Subject: [PATCH 7/7] Update v2.2.0.rst --- doc/source/whatsnew/v2.2.0.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v2.2.0.rst b/doc/source/whatsnew/v2.2.0.rst index e05aaff6d0f52..7bf9041412b74 100644 --- a/doc/source/whatsnew/v2.2.0.rst +++ b/doc/source/whatsnew/v2.2.0.rst @@ -727,11 +727,6 @@ Performance improvements Bug fixes ~~~~~~~~~ -- Bug in :class:`AbstractHolidayCalendar` where timezone data was not propagated when computing holiday observances (:issue:`54580`) -- Bug in :class:`pandas.core.window.Rolling` where duplicate datetimelike indexes are treated as consecutive rather than equal with ``closed='left'`` and ``closed='neither'`` (:issue:`20712`) -- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`) -- Bug in :meth:`pandas.read_excel` with a ODS file without cached formatted cell for float values (:issue:`55219`) -- 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`) Categorical ^^^^^^^^^^^ @@ -905,6 +900,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`) .. ---------------------------------------------------------------------------