Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; 'skip': 0.04; 'patterns': 0.05; 'unexpected': 0.07; 'url:py': 0.07; '[1]:': 0.09; '[2]:': 0.09; '[3]:': 0.09; 'subject:method': 0.09; 'url:github': 0.09; 'error:': 0.10; '**kwargs):': 0.16; '*args,': 0.16; '0))': 0.16; 'alchemy': 0.16; 'passed.': 0.16; 'self)': 0.16; 'subject:function': 0.16; 'subject:python.': 0.16; 'subject:release': 0.16; 'url:blob': 0.16; '\xa0def': 0.16; 'instance': 0.18; 'occurred': 0.18; 'input': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'fine': 0.24; 'traceback': 0.24; 'says': 0.25; 'tests': 0.25; 'code': 0.25; 'suggestion': 0.26; 'import': 0.27; 'code,': 0.27; 'invalid': 0.28; 'message- id:@mail.gmail.com': 0.28; 'error': 0.29; 'class': 0.29; 'lines': 0.30; 'subject:support': 0.30; 'returning': 0.32; 'received:209.85.160': 0.33; 'object': 0.33; 'to:addr:python- list': 0.34; 'something': 0.35; 'received:209.85.160.46': 0.35; 'received:mail-pw0-f46.google.com': 0.35; 'operating': 0.35; 'similar': 0.36; 'to:name:python-list': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'problems': 0.37; 'skip:_ 10': 0.37; 'doing': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'skip:o 20': 0.38; 'first.': 0.39; "i'd": 0.39; 'should': 0.39; 'subject: (': 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'move': 0.40; 'personal': 0.60; 'more': 0.61; 'body': 0.61; 'love': 0.62; 'soon.': 0.71; 'heavy': 0.71; 'corrupted': 0.84; 'nathan': 0.84; 'other):': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=rp2/3xLdvzhe/D+yeFFHls8WUGP3SQUmn05g/pwLRds=; b=Uw0bOhqzgonbr/9q7C1NxD6ZYWvQJR65p6WZ5NfztFr9ub4xPh2jV9VFme5CtuRtwU acNhN+Lb5Hnhdr+mEIpzGZv0zTdvV0Go1rnLfycEuxdeJlofWCH4pfUMyFyEXjOdCpbB VR8fplZMzSybvLTOGeJRaikoJ7pDkpHcV2UAI= MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 21 Dec 2011 10:15:38 -0500 Subject: Re: Elementwise -//- first release -//- Element-wise (vectorized) function, method and operator support for iterables in python. From: Nathan Rice To: python-list Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324480542 news.xs4all.nl 6963 [2001:888:2000:d::a6]:49030 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17667 > Have you seen PyLINQ? It has a similar approach to operating on > collections, returning a PyLINQ object after each call to facilitate > chaining. https://github.com/kalessin/PyLINQ/blob/master/pylinq/linq.py I hadn't seen it previously. I am a VERY heavy user of SQL Alchemy though, and I am sure chaining generative ClauseElements/Queries/etc, has burned some patterns into my subconscious at this point. > This is a personal opinion on the code, but I'd move instantiating the > new ElementwiseProxy out of each method and into its own decorator: > > =A0 =A0# declare this outside of the class > =A0 =A0def chainable(fn): > =A0 =A0 =A0 =A0def _(self, *args, **kwargs): > =A0 =A0 =A0 =A0 =A0 =A0return ElementwiseProxy(fn(self, *args, **kwargs),= self) > =A0 =A0 =A0 =A0return _ > > This way, each method that is chainable is a little more obvious > without inspecting the code, and the method body itself is only doing > what the method says it does: > > =A0 =A0@chainable > =A0 =A0def __add__(self, other): > =A0 =A0 =A0 =A0return (e + other for e in object.__getattribute__(self, > "iterable")) This is a reasonable suggestion and I will play with something along those lines soon. > Incidentally, displaying an ElementwiseProxy instance doesn't go down > well with iPython: > > In [1]: from elementwise import * > > In [2]: e =3D ElementwiseProxy(['one','two','three']) > > In [3]: e > Out[3]: ERROR: An unexpected error occurred while tokenizing input > The following traceback may be corrupted or invalid > The error message is: ('EOF in multi-line statement', (6, 0)) I love IPython, but it has had known problems with iterators for years. A long time ago, I agonized over what I thought was a bug in my code where itertools.count would skip numbers in IPython, but my unit tests all passed. Everything should work fine if you tuple() it first. Nathan