Skip to content

BUG: eval not working with string containment #64391

@moi90

Description

@moi90

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

# Create a sample DataFrame
df = pd.DataFrame(
    {
        "value": ["foobar", "foobaz", "bar", "baz"],
    }
)


expected_result = [True, True, False, False]

for expression in ['"foo" in value', "contains(value, 'foo')"]:
    print(f"Testing expression: {expression}")
    for engine in ["python", "numexpr"]:
        for parser in ["pandas", "python"]:
            try:
                result = df.eval(expression, engine=engine, parser=parser)  # type: ignore
            except Exception as e:
                print(f"engine={engine}, parser={parser}: {type(e).__name__}: {e}")
                continue

            if result.tolist() != expected_result:
                print(
                    f"engine={engine}, parser={parser}: {result.tolist()} != {expected_result}"
                )
                continue

            print(f"engine={engine}, parser={parser}: OK")
    print()

Issue Description

Output:

Testing expression: "foo" in value
engine=python, parser=pandas: [False, False, False, False] != [True, True, False, False]
engine=python, parser=python: NotImplementedError: 'In' nodes are not implemented
engine=numexpr, parser=pandas: [False, False, False, False] != [True, True, False, False]
engine=numexpr, parser=python: NotImplementedError: 'In' nodes are not implemented

Testing expression: contains(value, 'foo')
engine=python, parser=pandas: ValueError: "contains" is not a supported function
engine=python, parser=python: ValueError: "contains" is not a supported function
engine=numexpr, parser=pandas: ValueError: "contains" is not a supported function
engine=numexpr, parser=python: ValueError: "contains" is not a supported function

For no combination of containment test, engine or parser it is possible to check if a string is contained in the values of a column.

Expected Behavior

It should be possible to test if a string is contained in another string.

contains should at least work with numexpr because it is in the list of supported functions.

Installed Versions

Details

INSTALLED VERSIONS

commit : 366ccdf
python : 3.13.4
python-bits : 64
OS : Linux
OS-release : 6.17.0-14-generic
Version : #14~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 15 15:52:10 UTC 2
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8

pandas : 3.0.0
numpy : 2.2.5
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : 8.2.3
IPython : 9.10.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : 2025.3.2
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : None
numba : None
numexpr : 2.10.2
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : 20.0.0
pyiceberg : None
pyreadstat : None
pytest : 9.0.2
python-calamine : None
pytz : 2025.2
pyxlsb : None
s3fs : None
scipy : 1.15.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions