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" <[email protected]>
Sent: ‎11/‎10/‎2016 18:09
To: "Nathaniel Smith" <[email protected]>
Cc: "Eric V. Smith" <[email protected]>; "Python-Ideas" 
<[email protected]>
Subject: Re: [Python-ideas] Alternative to PEP 532: delayed evaluation 
ofexpressions

On Sun, Nov 6, 2016 at 5:32 PM, Nathaniel Smith <[email protected]> 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
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to