diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 6239ddf9442e7..736beffe0418e 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -194,6 +194,7 @@ Removal of prior version deprecations/changes - Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`) - Remove ``numpy`` argument from :func:`read_json` (:issue:`30636`) - Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`) +- Removed the ``truediv`` keyword from :func:`eval` (:issue:`29812`) - Removed the ``pandas.datetime`` submodule (:issue:`30489`) - Removed the ``pandas.np`` submodule (:issue:`30296`) - Removed ``pandas.SparseArray`` in favor of :class:`arrays.SparseArray` (:issue:`30642`) diff --git a/pandas/core/computation/eval.py b/pandas/core/computation/eval.py index baf8c837d7f78..bc8c37b9273ce 100644 --- a/pandas/core/computation/eval.py +++ b/pandas/core/computation/eval.py @@ -7,8 +7,6 @@ from typing import TYPE_CHECKING import warnings -from pandas._libs.lib import no_default -from pandas.util._exceptions import find_stack_level from pandas.util._validators import validate_bool_kwarg from pandas.core.computation.engines import ENGINES @@ -171,7 +169,6 @@ def eval( expr: str | BinOp, # we leave BinOp out of the docstr bc it isn't for users parser: str = "pandas", engine: str | None = None, - truediv=no_default, local_dict=None, global_dict=None, resolvers=(), @@ -217,12 +214,6 @@ def eval( level python. This engine is generally not that useful. More backends may be available in the future. - - truediv : bool, optional - Whether to use true division, like in Python >= 3. - - .. deprecated:: 1.0.0 - local_dict : dict or None, optional A dictionary of local variables, taken from locals() by default. global_dict : dict or None, optional @@ -305,16 +296,6 @@ def eval( """ inplace = validate_bool_kwarg(inplace, "inplace") - if truediv is not no_default: - warnings.warn( - ( - "The `truediv` parameter in pd.eval is deprecated and " - "will be removed in a future version." - ), - FutureWarning, - stacklevel=find_stack_level(), - ) - exprs: list[str | BinOp] if isinstance(expr, str): _check_expression(expr) diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index 6548422c5d2b7..7fce4e9d9c38e 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -1105,40 +1105,6 @@ def test_single_variable(self): df2 = self.eval("df", local_dict={"df": df}) tm.assert_frame_equal(df, df2) - def test_truediv(self): - s = np.array([1]) # noqa:F841 - ex = "s / 1" - - # FutureWarning: The `truediv` parameter in pd.eval is deprecated and will be - # removed in a future version. - with tm.assert_produces_warning(FutureWarning): - res = self.eval(ex, truediv=False) - tm.assert_numpy_array_equal(res, np.array([1.0])) - - with tm.assert_produces_warning(FutureWarning): - res = self.eval(ex, truediv=True) - tm.assert_numpy_array_equal(res, np.array([1.0])) - - with tm.assert_produces_warning(FutureWarning): - res = self.eval("1 / 2", truediv=True) - expec = 0.5 - assert res == expec - - with tm.assert_produces_warning(FutureWarning): - res = self.eval("1 / 2", truediv=False) - expec = 0.5 - assert res == expec - - with tm.assert_produces_warning(FutureWarning): - res = self.eval("s / 2", truediv=False) - expec = 0.5 - assert res == expec - - with tm.assert_produces_warning(FutureWarning): - res = self.eval("s / 2", truediv=True) - expec = 0.5 - assert res == expec - def test_failing_subscript_with_name_error(self): df = DataFrame(np.random.randn(5, 3)) # noqa:F841 with pytest.raises(NameError, match="name 'x' is not defined"): @@ -1859,23 +1825,6 @@ def test_inf(engine, parser): assert result == expected -def test_truediv_deprecated(engine, parser): - # GH#29182 - match = "The `truediv` parameter in pd.eval is deprecated" - - with tm.assert_produces_warning(FutureWarning) as m: - pd.eval("1+1", engine=engine, parser=parser, truediv=True) - - assert len(m) == 1 - assert match in str(m[0].message) - - with tm.assert_produces_warning(FutureWarning) as m: - pd.eval("1+1", engine=engine, parser=parser, truediv=False) - - assert len(m) == 1 - assert match in str(m[0].message) - - @pytest.mark.parametrize("column", ["Temp(°C)", "Capacitance(μF)"]) def test_query_token(engine, column): # See: https://github.com/pandas-dev/pandas/pull/42826