{"record":{"id":"5529d192132d5448","repo":"pandas-dev/pandas","slug":"cannot-operate-inplace-if-there-is-no-assignment","errorCode":null,"errorMessage":"Cannot operate inplace if there is no assignment","messagePattern":"Cannot operate inplace if there is no assignment","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/computation/eval.py","lineNumber":409,"sourceCode":"                \"extension array dtypes. Please set your engine to python manually.\",\n                RuntimeWarning,\n                stacklevel=find_stack_level(),\n            )\n            engine = \"python\"\n\n        # construct the engine and evaluate the parsed expression\n        eng = ENGINES[engine]\n        eng_inst = eng(parsed_expr)\n        ret = eng_inst.evaluate()\n\n        if parsed_expr.assigner is None:\n            if multi_line:\n                raise ValueError(\n                    \"Multi-line expressions are only valid \"\n                    \"if all expressions contain an assignment\"\n                )\n            if inplace:\n                raise ValueError(\"Cannot operate inplace if there is no assignment\")\n\n        # assign if needed\n        assigner = parsed_expr.assigner\n        if env.target is not None and assigner is not None:\n            target_modified = True\n\n            # if returning a copy, copy only on the first assignment\n            if not inplace and first_expr:\n                try:\n                    target = env.target\n                    if isinstance(target, NDFrame):\n                        target = target.copy(deep=False)\n                    else:\n                        target = target.copy()\n                except AttributeError as err:\n                    raise ValueError(\"Cannot return a copy of the target\") from err\n            else:\n                target = env.target","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/computation/eval.py#L391-L427","documentation":"Raised after evaluation when parsed_expr.assigner is None (no assignment in the expression) but inplace=True was requested. Inplace operation only makes sense when there is a column/variable to mutate; without an assignment target inside the expression, there is nothing to operate on inplace.","triggerScenarios":"Calling df.eval('a + b', inplace=True) — the expression 'a + b' produces a value but does not assign it, so inplace has no effect and is rejected.","commonSituations":"Setting inplace=True globally or in a wrapper that always passes it; misunderstanding that inplace applies to the assignment target inside the expression, not to returning a value.","solutions":["Add an assignment to the expression: df.eval('c = a + b', inplace=True).","Drop inplace=True if you only want the computed value: result = df.eval('a + b')."],"exampleFix":"// before\ndf.eval('a + b', inplace=True)\n\n// after\ndf.eval('c = a + b', inplace=True)","handlingStrategy":"validation","validationCode":"has_assignment = isinstance(expr, str) and '=' in expr.splitlines()[0]\nif inplace and not has_assignment:\n    raise ValueError('inplace=True requires an assignment expression')\ndf.eval(expr, inplace=inplace)","typeGuard":null,"tryCatchPattern":"try:\n    df.eval(expr, inplace=True)\nexcept ValueError as e:\n    if 'no assignment' in str(e):\n        result = df.eval(expr, inplace=False)\n    else:\n        raise","preventionTips":["Only use inplace=True when the expression assigns a column.","Drop inplace if you only need the computed value.","Document the relationship between inplace and assignment."],"tags":["pandas","eval","inplace","assignment","argument-error"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}