Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
df = pd.DataFrame({"first": [9.76, 9.76, 9.76], "last": [9.76, 9.76, 9.76], "pre": [9.75, 9.76, 9.76]})
expr = """first_ret = first / pre.fillna(first) - 1.0
last_ret = last / pre.fillna(first) - 1.0"""
# this fails with `TypeError: "value" parameter must be a scalar, dict or Series, but you passed a "ndarray"`
df.eval(expr)
# this works fine
for line in expr.splitlines():
df.eval(line)
Issue Description
DataFrame.eval fails with TypeError: "value" parameter must be a scalar, dict or Series, but you passed a "ndarray" with multiline expr but works when eval line by line.
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
DataFrame.eval
fails withTypeError: "value" parameter must be a scalar, dict or Series, but you passed a "ndarray"
with multiline expr but works wheneval
line by line.The culprit seems to be that https://github.com/pandas-dev/pandas/blob/a60ad39b4a9febdea9a59d602dad44b1538b0ea5/pandas/core/computation/align.py#L140 modified
Scope.resolvers
.Expected Behavior
df.eval(expr)
also works fineInstalled Versions