-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
Is your feature request related to a problem?
the evaluation of a query is currently limited to the list _mathops
while numexpr would support more, most notably a where (that would also solve other issues simple).
I do not see any reason for this restriction. In fact, simply adding the where
runs (at least for my use case). Why is this restriction in place? Why can't we enlarge it/directly pass it through to numexpr?
Describe the solution you'd like
Allow the full operator set that numexpr supports in the pd.eval
API breaking implications
Nothing
Alternatives
Using .where
is an option if you can access the dataframe directly (although suboptimal). However, if your selection of data is based on passing a selection string around instead of the df (several reasons for this), the latter is not feasible.
The following doesn't work:
import pandas as pd
data = {'a': [1, 2, 3]}
df = pd.DataFrame({'a': [1, 2, 3]})
df.eval('where(a>2, 42, 0)')
whereas in numexpr
it does
numexpr.evaluate('where(a>2, 42, 0)', local_dict=data)
we expect this to return [0, 0, 42]