Skip to content

BUG: Fix DataFrame.eval to return scalar for string literal with in/not in operators#65037

Open
deniskrds wants to merge 3 commits intopandas-dev:mainfrom
deniskrds:fix-eval-string-in-operator
Open

BUG: Fix DataFrame.eval to return scalar for string literal with in/not in operators#65037
deniskrds wants to merge 3 commits intopandas-dev:mainfrom
deniskrds:fix-eval-string-in-operator

Conversation

@deniskrds
Copy link
Copy Markdown
Contributor

  • closes BUG: eval not working with string containment #64391
  • [Tests added and passed] if fixing a bug or adding a new feature
  • All [code checks passed].
  • Added [type annotations] to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/v3.1.0.rst file if fixing a bug or adding a new feature.
  • I have reviewed and followed all the [contribution guidelines]
  • If I used AI to develop this pull request, I prompted it to follow AGENTS.md.

df.eval('"foo" in value') returned Series([False, False, ...]) instead of a scalar boolean.
The root cause was _rewrite_membership_op wrapping the string literal "foo" into ["foo"], causing Series.isin(["foo"]) to run — an exact equality check that always returned False for non-exact matches.

Fix applied as skipping the wrapping when the operator is already in/not in, so it falls through to Python's native x in y semantics and returns a scalar correctly.

@deniskrds deniskrds changed the title Fix eval string in operator BUG: Fix DataFrame.eval to return scalar for string literal with in/not in operators Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: eval not working with string containment

1 participant