Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP: Remove truediv from eval #49267

Merged
merged 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
19 changes: 0 additions & 19 deletions pandas/core/computation/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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=(),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
51 changes: 0 additions & 51 deletions pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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
Expand Down