[Numpy-discussion] Shouldn't all in-place operations simply return self?

eat e.antero.tammi at gmail.com
Sat Jan 19 06:35:27 EST 2013


Hi,

On Fri, Jan 18, 2013 at 12:13 AM, Thouis (Ray) Jones <thouis at gmail.com>wrote:

> On Thu, Jan 17, 2013 at 10:27 AM, Charles R Harris
> <charlesr.harris at gmail.com> wrote:
> >
> >
> > On Wed, Jan 16, 2013 at 5:11 PM, eat <e.antero.tammi at gmail.com> wrote:
> >>
> >> Hi,
> >>
> >> In a recent thread
> >> http://article.gmane.org/gmane.comp.python.numeric.general/52772 it was
> >> proposed that .fill(.) should return self as an alternative for a
> trivial
> >> two-liner.
> >>
> >> I'm raising now the question: what if all in-place operations indeed
> could
> >> return self? How bad this would be? A 'strong' counter argument may be
> found
> >> at http://mail.python.org/pipermail/python-dev/2003-October/038855.html
> .
> >>
> >> But anyway, at least for me. it would be much more straightforward to
> >> implement simple mini dsl's
> >> (http://en.wikipedia.org/wiki/Domain-specific_language) a much more
> >> straightforward manner.
> >>
> >> What do you think?
> >>
> >
> > I've read Guido about why he didn't like inplace operations returning
> self
> > and found him convincing for a while. And then I listened to other folks
> > express a preference for the freight train style and found them
> convincing
> > also. I think it comes down to a preference for one style over another
> and I
> > go back and forth myself. If I had to vote, I'd go for returning self,
> but
> > I'm not sure it's worth breaking python conventions to do so.
> >
> > Chuck
>
> I'm -1 on breaking with Python convention without very good reasons.
>
As an example I personally find following behavior highly counter intuitive.
In []: p, P= rand(3, 1), rand(3, 5)

In []: ((p- P)** 2).sum(0).argsort()
Out[]: array([2, 4, 1, 3, 0])

In []: ((p- P)** 2).sum(0).sort().diff()
------------------------------------------------------------
Traceback (most recent call last):
  File "<ipython console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'diff'


Regards,
-eat

>
> Ray
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130119/3c2ea045/attachment.html>


More information about the NumPy-Discussion mailing list