[Python-ideas] The pipe protocol, a convention for extensible method chaining

M.-A. Lemburg mal at egenix.com
Wed May 27 10:45:39 CEST 2015


On 26.05.2015 01:38, Stephan Hoyer wrote:
> In the PyData community, we really like method chaining for data analysis
> pipelines:
> 
> (iris.query('SepalLength > 5')
>  .assign(SepalRatio = lambda x: x.SepalWidth / x.SepalLength,
>          PetalRatio = lambda x: x.PetalWidth / x.PetalLength)
>  .plot(kind='scatter', x='SepalRatio', y='PetalRatio'))

FWIW: I don't think this is a programming style we should encourage
in Python in general, so I'm -1 on this.

It doesn't read well, you cannot easily tell what the intermediate
objects are on which you run the methods, debugging the above becomes
hard, it only gives you a minor typing advantage over using variables
and calling methods on those and it gives you no performance
advantage.

If you need a pipe pattern, it would be better to make that
explicit through some special helper function or perhaps a
piping object on which you register the various steps to run.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, May 27 2015)
>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>> mxODBC Plone/Zope Database Adapter ...       http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the Python-ideas mailing list