From bf6fbe5d4b093a270e8f1bbb587f070455bf4d96 Mon Sep 17 00:00:00 2001 From: gfyoung Date: Mon, 19 Jun 2017 21:26:24 -0700 Subject: [PATCH] MAINT: Default inplace to False in pd.eval Deprecated back in 0.18.0 xref gh-11149 [ci skip] --- doc/source/whatsnew/v0.21.0.txt | 1 + pandas/core/computation/eval.py | 16 ++-------------- pandas/tests/computation/test_eval.py | 8 -------- 3 files changed, 3 insertions(+), 22 deletions(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 45c92717b60f09..e1665c60180235 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -76,6 +76,7 @@ Removal of prior version deprecations/changes - ``pd.read_excel()`` has dropped the ``has_index_names`` parameter (:issue:`10967`) - ``Categorical`` has dropped the ``.order()`` and ``.sort()`` methods in favor of ``.sort_values()`` (:issue:`12882`) +- ``pd.eval`` has changed the default of ``inplace`` from ``None`` to ``False`` (:issue:`11149`) .. _whatsnew_0210.performance: diff --git a/pandas/core/computation/eval.py b/pandas/core/computation/eval.py index 22e376306280ac..0b3ed252a8ce9f 100644 --- a/pandas/core/computation/eval.py +++ b/pandas/core/computation/eval.py @@ -148,7 +148,7 @@ def _check_for_locals(expr, stack_level, parser): def eval(expr, parser='pandas', engine=None, truediv=True, local_dict=None, global_dict=None, resolvers=(), level=0, - target=None, inplace=None): + target=None, inplace=False): """Evaluate a Python expression as a string using various backends. The following arithmetic operations are supported: ``+``, ``-``, ``*``, @@ -207,14 +207,10 @@ def eval(expr, parser='pandas', engine=None, truediv=True, scope. Most users will **not** need to change this parameter. target : a target object for assignment, optional, default is None essentially this is a passed in resolver - inplace : bool, default True + inplace : bool, default False If expression mutates, whether to modify object inplace or return copy with mutation. - WARNING: inplace=None currently falls back to to True, but - in a future version, will default to False. Use inplace=True - explicitly rather than relying on the default. - Returns ------- ndarray, numeric scalar, DataFrame, Series @@ -272,14 +268,6 @@ def eval(expr, parser='pandas', engine=None, truediv=True, # assign if needed if env.target is not None and parsed_expr.assigner is not None: - if inplace is None: - warnings.warn( - "eval expressions containing an assignment currently" - "default to operating inplace.\nThis will change in " - "a future version of pandas, use inplace=True to " - "avoid this warning.", - FutureWarning, stacklevel=3) - inplace = True # if returning a copy, copy only on the first assignment if not inplace and first_expr: diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index 89ab4531877a4e..c214f7c68efe83 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -1311,14 +1311,6 @@ def assignment_not_inplace(self): expected['c'] = expected['a'] + expected['b'] tm.assert_frame_equal(df, expected) - # Default for inplace will change - with tm.assert_produces_warnings(FutureWarning): - df.eval('c = a + b') - - # but don't warn without assignment - with tm.assert_produces_warnings(None): - df.eval('a + b') - def test_multi_line_expression(self): # GH 11149 df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})