Skip to content

Commit 886f841

Browse files
authored
DEP: Remove truediv from eval (#49267)
* DEP: Remove truediv from eval * Remove test
1 parent a6e61fe commit 886f841

File tree

3 files changed

+1
-70
lines changed

3 files changed

+1
-70
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ Removal of prior version deprecations/changes
197197
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)
198198
- Remove ``numpy`` argument from :func:`read_json` (:issue:`30636`)
199199
- Removed the ``center`` keyword in :meth:`DataFrame.expanding` (:issue:`20647`)
200+
- Removed the ``truediv`` keyword from :func:`eval` (:issue:`29812`)
200201
- Removed the ``pandas.datetime`` submodule (:issue:`30489`)
201202
- Removed the ``pandas.np`` submodule (:issue:`30296`)
202203
- Removed ``pandas.SparseArray`` in favor of :class:`arrays.SparseArray` (:issue:`30642`)

pandas/core/computation/eval.py

-19
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from typing import TYPE_CHECKING
88
import warnings
99

10-
from pandas._libs.lib import no_default
11-
from pandas.util._exceptions import find_stack_level
1210
from pandas.util._validators import validate_bool_kwarg
1311

1412
from pandas.core.computation.engines import ENGINES
@@ -171,7 +169,6 @@ def eval(
171169
expr: str | BinOp, # we leave BinOp out of the docstr bc it isn't for users
172170
parser: str = "pandas",
173171
engine: str | None = None,
174-
truediv=no_default,
175172
local_dict=None,
176173
global_dict=None,
177174
resolvers=(),
@@ -217,12 +214,6 @@ def eval(
217214
level python. This engine is generally not that useful.
218215
219216
More backends may be available in the future.
220-
221-
truediv : bool, optional
222-
Whether to use true division, like in Python >= 3.
223-
224-
.. deprecated:: 1.0.0
225-
226217
local_dict : dict or None, optional
227218
A dictionary of local variables, taken from locals() by default.
228219
global_dict : dict or None, optional
@@ -305,16 +296,6 @@ def eval(
305296
"""
306297
inplace = validate_bool_kwarg(inplace, "inplace")
307298

308-
if truediv is not no_default:
309-
warnings.warn(
310-
(
311-
"The `truediv` parameter in pd.eval is deprecated and "
312-
"will be removed in a future version."
313-
),
314-
FutureWarning,
315-
stacklevel=find_stack_level(),
316-
)
317-
318299
exprs: list[str | BinOp]
319300
if isinstance(expr, str):
320301
_check_expression(expr)

pandas/tests/computation/test_eval.py

-51
Original file line numberDiff line numberDiff line change
@@ -1105,40 +1105,6 @@ def test_single_variable(self):
11051105
df2 = self.eval("df", local_dict={"df": df})
11061106
tm.assert_frame_equal(df, df2)
11071107

1108-
def test_truediv(self):
1109-
s = np.array([1]) # noqa:F841
1110-
ex = "s / 1"
1111-
1112-
# FutureWarning: The `truediv` parameter in pd.eval is deprecated and will be
1113-
# removed in a future version.
1114-
with tm.assert_produces_warning(FutureWarning):
1115-
res = self.eval(ex, truediv=False)
1116-
tm.assert_numpy_array_equal(res, np.array([1.0]))
1117-
1118-
with tm.assert_produces_warning(FutureWarning):
1119-
res = self.eval(ex, truediv=True)
1120-
tm.assert_numpy_array_equal(res, np.array([1.0]))
1121-
1122-
with tm.assert_produces_warning(FutureWarning):
1123-
res = self.eval("1 / 2", truediv=True)
1124-
expec = 0.5
1125-
assert res == expec
1126-
1127-
with tm.assert_produces_warning(FutureWarning):
1128-
res = self.eval("1 / 2", truediv=False)
1129-
expec = 0.5
1130-
assert res == expec
1131-
1132-
with tm.assert_produces_warning(FutureWarning):
1133-
res = self.eval("s / 2", truediv=False)
1134-
expec = 0.5
1135-
assert res == expec
1136-
1137-
with tm.assert_produces_warning(FutureWarning):
1138-
res = self.eval("s / 2", truediv=True)
1139-
expec = 0.5
1140-
assert res == expec
1141-
11421108
def test_failing_subscript_with_name_error(self):
11431109
df = DataFrame(np.random.randn(5, 3)) # noqa:F841
11441110
with pytest.raises(NameError, match="name 'x' is not defined"):
@@ -1859,23 +1825,6 @@ def test_inf(engine, parser):
18591825
assert result == expected
18601826

18611827

1862-
def test_truediv_deprecated(engine, parser):
1863-
# GH#29182
1864-
match = "The `truediv` parameter in pd.eval is deprecated"
1865-
1866-
with tm.assert_produces_warning(FutureWarning) as m:
1867-
pd.eval("1+1", engine=engine, parser=parser, truediv=True)
1868-
1869-
assert len(m) == 1
1870-
assert match in str(m[0].message)
1871-
1872-
with tm.assert_produces_warning(FutureWarning) as m:
1873-
pd.eval("1+1", engine=engine, parser=parser, truediv=False)
1874-
1875-
assert len(m) == 1
1876-
assert match in str(m[0].message)
1877-
1878-
18791828
@pytest.mark.parametrize("column", ["Temp(°C)", "Capacitance(μF)"])
18801829
def test_query_token(engine, column):
18811830
# See: https://github.com/pandas-dev/pandas/pull/42826

0 commit comments

Comments
 (0)