[Python-ideas] Alternative to PEP 532: delayed evaluation ofexpressions

Steve Dower steve.dower at python.org
Sat Nov 12 09:06:15 EST 2016


Would it be helped by an explicit "free variable" marker? (I'm sure I've seen someone demo a prototype of this):

>>> data_frame.subset($height > 100 and $age < 5)

Which essentially translates into:

>>> data_frame.subset(lambda **a: a["height"] > 100 and a["age"] < 5)

Maybe the generated thunk can keep the AST around too in case there are better transformations available (e.g. convert into a SQL/Blaze query), but simply calling it with named arguments or a mapping (I am deliberately not requiring the eventual caller to know the exact signature) would get you the result with a mix of closed and free variables.

Cheers,
Steve

Top-posted from my Windows Phone

-----Original Message-----
From: "Stephan Hoyer" <shoyer at gmail.com>
Sent: ‎11/‎10/‎2016 18:09
To: "Nathaniel Smith" <njs at pobox.com>
Cc: "Eric V. Smith" <eric at trueblade.com>; "Python-Ideas" <python-ideas at python.org>
Subject: Re: [Python-ideas] Alternative to PEP 532: delayed evaluation ofexpressions

On Sun, Nov 6, 2016 at 5:32 PM, Nathaniel Smith <njs at pobox.com> wrote:

Filtering out a subset of rows from a data frame in pandas; 'height'

and 'age' refer to columns in the data frame (equivalent to
data_frame[data_frame["height"] > 100 and data_frame["age"] < 5], but
more ergonomic and faster (!)):

    data_frame.subset!(height > 100 and age < 5)

(IIRC pandas has at least experimented with various weird lambda hacks
for this kind of thing; not sure what the current status is.)



We abandoned the experiment because we couldn't make it work properly. There's no way to inject local variables in the appropriate scope around the lambda function:
https://github.com/pandas-dev/pandas/issues/13040
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161112/e428cdf0/attachment.html>


More information about the Python-ideas mailing list