[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-ideas
Subject:    Re: [Python-ideas] Alternative to PEP 532: delayed evaluation ofexpressions
From:       Steve Dower <steve.dower () python ! org>
Date:       2016-11-12 14:06:15
Message-ID: E1c5YxA-0006NB-LH () se2-syd ! hostedmail ! net ! au
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@gmail.com>
Sent: ‎11/‎10/‎2016 18:09
To: "Nathaniel Smith" <njs@pobox.com>
Cc: "Eric V. Smith" <eric@trueblade.com>; "Python-Ideas" <python-ideas@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@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


[Attachment #5 (unknown)]

<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>&gt;&gt;&gt; \
data_frame.subset($height &gt; 100 and $age &lt; 5)<br><br>Which essentially \
translates into:<br><br>&gt;&gt;&gt; data_frame.subset(lambda **a: a["height"] &gt; \
100 and a["age"] &lt; 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">&lt;<a href="mailto:njs@pobox.com" \
target="_blank">njs@pobox.com</a>&gt;</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>] &gt; 100 and \
data_frame["age"] &lt; 5], but<br> more ergonomic and faster (!)):<br>
<br>
&nbsp; &nbsp; data_frame.subset!(height &gt; 100 and age &lt; 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>



_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic