<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><div><div style="font-family: Calibri,sans-serif; font-size: 11pt;">Would it be helped by an explicit "free variable" marker? (I'm sure I've seen someone demo a prototype of this):<br><br>>>> data_frame.subset($height > 100 and $age < 5)<br><br>Which essentially translates into:<br><br>>>> data_frame.subset(lambda **a: a["height"] > 100 and a["age"] < 5)<br><br>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.<br><br>Cheers,<br>Steve<br><br>Top-posted from my Windows Phone</div></div><div dir="ltr"><hr><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">From: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:shoyer@gmail.com">Stephan Hoyer</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Sent: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">‎11/‎10/‎2016 18:09</span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">To: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:njs@pobox.com">Nathaniel Smith</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Cc: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;"><a href="mailto:eric@trueblade.com">Eric V. Smith</a>; <a href="mailto:python-ideas@python.org">Python-Ideas</a></span><br><span style="font-family: Calibri,sans-serif; font-size: 11pt; font-weight: bold;">Subject: </span><span style="font-family: Calibri,sans-serif; font-size: 11pt;">Re: [Python-ideas] Alternative to PEP 532: delayed evaluation ofexpressions</span><br><br></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Nov 6, 2016 at 5:32 PM, Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"><div class="gmail-HOEnZb"><div class="gmail-h5"><span style="color: rgb(34, 34, 34);">Filtering out a subset of rows from a data frame in pandas; 'height'</span><br></div></div>
and 'age' refer to columns in the data frame (equivalent to<br>
data_frame[data_frame["height"<wbr>] > 100 and data_frame["age"] < 5], but<br>
more ergonomic and faster (!)):<br>
<br>
    data_frame.subset!(height > 100 and age < 5)<br>
<br>
(IIRC pandas has at least experimented with various weird lambda hacks<br>
for this kind of thing; not sure what the current status is.)<br></blockquote><div><br></div><div>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:</div><div><a href="https://github.com/pandas-dev/pandas/issues/13040">https://github.com/pandas-dev/pandas/issues/13040</a></div></div></div></div>
</body></html>