Syntactic sugar for parent in __setitem__ and __getitem__ to improve boolean indexing

In limited contexts like a panda’s data-frame I don’t see that parsing:

  1           0 LOAD_FAST                0 (df)
              2 LOAD_ATTR                0 (column_1)
              4 LOAD_CONST               1 (5)
              6 COMPARE_OP               4 (>)
              8 RETURN_VALUE

Is much different than parsing:

column_1 > 5

And assuming you aren’t trying to do anything more than the panda’s query command does (which parses very limited expressions, like one above, in the context of data frames).

But sure, in general Python byte code to GPU is hard.

Bigger picture, short lambda expressions would be great in many areas!

1 Like

There is precedent in Scala for writing anonymous functions like this, much more succinctly than Python allows:

Anonymous Functions | Scala Book | Scala Documentation

For example, the expression _ * 2 (or more verbosely x => x * 2) creates the Scala equivalent of lambda x: x * 2. Using something like that would be nice (here using the _ as in Scala):

dataframe[_.height > 5 & _.weight < 200]

The notion of expressing a function like this becomes quite natural once you’ve used it a few times - it’s an underspecified expression with “holes” in it, which will perform a computation once the holes have been assigned values. Just like a simple function containing one expression (a Python lambda).