Re: Rich Comparisons Gotcha

2009-01-07 Thread Steven D'Aprano
On Wed, 07 Jan 2009 01:23:19 +, Mark Wooding wrote: A case-sensitive string is /not the same/ as a case-insensitive string. One's a duck, the other's a goose. I'd claim here that iabc =~ ABC must be False, because iabc =~ abc must be false also! To define it otherwise leads to the

Re: Rich Comparisons Gotcha

2009-01-07 Thread Mark Wooding
Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: It's only incoherent if you need equality to be an equivalence relation. If you don't, it is perfectly reasonable to declare that iabc equals abc. Right! And if you didn't want an equivalence relation, then `==' will suit you

Re: Rich Comparisons Gotcha

2009-01-06 Thread Mark Wooding
Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: Such assumptions only hold under particular domains though. You can't assume equality is an equivalence relation once you start thinking about arbitrary domains. From a formal mathematical point of view, equality /is/ an equivalence

Re: Rich Comparisons Gotcha

2009-01-06 Thread Steven D'Aprano
On Tue, 06 Jan 2009 12:42:13 +, Mark Wooding wrote: Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: Such assumptions only hold under particular domains though. You can't assume equality is an equivalence relation once you start thinking about arbitrary domains. From a

Re: Rich Comparisons Gotcha

2009-01-06 Thread Mark Wooding
Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: To prove my claim, all you need is two domains with a mutually incompatible definition of equality. That's not so difficult, surely? How about equality of integers, versus equality of integers modulo some N? No, that's not an

Re: Rich Comparisons Gotcha

2009-01-05 Thread Mark Wooding
Steven D'Aprano st...@remove-this-cybersource.com.au wrote: There is nothing to blame them for. This is the correct behaviour. NaNs should *not* compare equal to themselves, that's mathematically incoherent. Indeed. The problem is a paucity of equality predicates. This is hardly

Re: Rich Comparisons Gotcha

2009-01-05 Thread Mark Wooding
Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: I've already mentioned NaNs. Sentinel values also sometimes need to compare not equal with themselves. Forcing them to compare equal will cause breakage. There's a conflict between such domain-specific considerations (NaNs, strange

Re: Rich Comparisons Gotcha

2009-01-05 Thread Steven D'Aprano
On Tue, 06 Jan 2009 01:24:58 +, Mark Wooding wrote: Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: I've already mentioned NaNs. Sentinel values also sometimes need to compare not equal with themselves. Forcing them to compare equal will cause breakage. There's a

Re: Rich Comparisons Gotcha

2008-12-11 Thread Steven D'Aprano
On Wed, 10 Dec 2008 17:58:49 -0500, Luis Zarrabeitia wrote: On Sunday 07 December 2008 09:21:18 pm Robert Kern wrote: The deficiency is in the feature of rich comparisons, not numpy's implementation of it. __eq__() is allowed to return non-booleans; however, there are some parts of Python's

Re: Rich Comparisons Gotcha

2008-12-11 Thread M.-A. Lemburg
On 2008-12-10 23:21, Luis Zarrabeitia wrote: On Wednesday 10 December 2008 02:44:45 pm you wrote: Even in statically typed languages, when you override the equality operator/function you can choose not to return a valid answer (raise an exception). And it would break all the cases mentioned

Re: Rich Comparisons Gotcha

2008-12-10 Thread Rasmus Fogh
Rhamphoryncus wrote: You grossly overvalue using the in operator on lists. Maybe. But there is more to it than just 'in'. If you do: c = numpy.zeros((2,)) ll = [1, c, 3.] then the following all throw errors: 3 in ll, 3 not in ll, ll.index(3), ll.count(3), ll.remove(3) c in ll, c not in ll,

Re: Rich Comparisons Gotcha

2008-12-10 Thread Rasmus Fogh
Rhodri James wrote: On Mon, 08 Dec 2008 14:24:59 -, Rasmus Fogh wrote: On the minus side there would be the difference between '__equal__' and '__eq__' to confuse people. This is a very big minus. It would be far better to spell __equal__ in such a way as to make it clear why it

Re: Rich Comparisons Gotcha

2008-12-10 Thread Luis Zarrabeitia
Quoting Rasmus Fogh [EMAIL PROTECTED]: Rhamphoryncus wrote: You grossly overvalue using the in operator on lists. Maybe. But there is more to it than just 'in'. If you do: c = numpy.zeros((2,)) ll = [1, c, 3.] then the following all throw errors: 3 in ll, 3 not in ll, ll.index(3),

Re: Rich Comparisons Gotcha

2008-12-10 Thread M.-A. Lemburg
On 2008-12-10 16:40, Luis Zarrabeitia wrote: Quoting Rasmus Fogh [EMAIL PROTECTED]: Rhamphoryncus wrote: You grossly overvalue using the in operator on lists. Maybe. But there is more to it than just 'in'. If you do: c = numpy.zeros((2,)) ll = [1, c, 3.] then the following all throw errors:

Re: Rich Comparisons Gotcha

2008-12-10 Thread Rhamphoryncus
On Dec 10, 7:49 am, Rasmus Fogh [EMAIL PROTECTED] wrote: Rhamphoryncus wrote: You grossly overvalue using the in operator on lists. Maybe. But there is more to it than just 'in'. If you do: c = numpy.zeros((2,)) ll = [1, c, 3.] then the following all throw errors: 3 in ll, 3 not in ll,

Re: Rich Comparisons Gotcha

2008-12-10 Thread Terry Reedy
Rasmus Fogh wrote: Rhamphoryncus wrote: You grossly overvalue using the in operator on lists. Maybe. But there is more to it than just 'in'. If you do: c = numpy.zeros((2,)) ll = [1, c, 3.] then the following all throw errors: 3 in ll, 3 not in ll, ll.index(3), ll.count(3), ll.remove(3) c

Re: Rich Comparisons Gotcha

2008-12-10 Thread Luis Zarrabeitia
On Wednesday 10 December 2008 10:50:57 am M.-A. Lemburg wrote: On 2008-12-10 16:40, Luis Zarrabeitia wrote: Quoting Rasmus Fogh [EMAIL PROTECTED]: Rhamphoryncus wrote: Rich comparisons were added to Python at the request of the Numeric (now numpy) developers and they have been part of

Re: Rich Comparisons Gotcha

2008-12-10 Thread M.-A. Lemburg
On 2008-12-10 20:01, Luis Zarrabeitia wrote: On Wednesday 10 December 2008 10:50:57 am M.-A. Lemburg wrote: On 2008-12-10 16:40, Luis Zarrabeitia wrote: Quoting Rasmus Fogh [EMAIL PROTECTED]: Rhamphoryncus wrote: Rich comparisons were added to Python at the request of the Numeric (now numpy)

Re: Rich Comparisons Gotcha

2008-12-10 Thread Luis Zarrabeitia
On Wednesday 10 December 2008 02:44:45 pm you wrote: Even in statically typed languages, when you override the equality operator/function you can choose not to return a valid answer (raise an exception). And it would break all the cases mentioned above (element in list, etc). But that

Re: Rich Comparisons Gotcha

2008-12-10 Thread Luis Zarrabeitia
On Sunday 07 December 2008 09:21:18 pm Robert Kern wrote: The deficiency is in the feature of rich comparisons, not numpy's implementation of it. __eq__() is allowed to return non-booleans; however, there are some parts of Python's implementation like list.__contains__() that still expect the

Re: Rich Comparisons Gotcha

2008-12-10 Thread Steven D'Aprano
On Wed, 10 Dec 2008 17:21:51 -0500, Luis Zarrabeitia wrote: I do numeric work... I'm finishing my MSc in applied math and I'm programing mostly with python. And I'd rather have a.compare_with(b), or a.elementwise_compare(b), or whatever name, rather than (a==b).all(). Unluckily for you, the

Re: Rich Comparisons Gotcha

2008-12-09 Thread Rasmus Fogh
Steven DAprano wrote: On Mon, 08 Dec 2008 14:24:59 +, Rasmus Fogh wrote: For my personal problem I could indeed wrap all objects in a wrapper with whatever 'correct' behaviour I want (thanks, TJR). It does seem a bit much, though, just to get code like this to work as intended:

Re: Rich Comparisons Gotcha

2008-12-09 Thread Rasmus Fogh
Steven DAprano wrote: On Mon, 08 Dec 2008 14:24:59 +, Rasmus Fogh wrote: snip What might be a sensible behaviour (unlike your proposed wrapper) Sorry 1) I was rude, 2) I thanked TJR for your wrapper class proposal in a later mail. It is yours. What do you dislike about my wrapper class?

Re: Rich Comparisons Gotcha

2008-12-09 Thread Mark Dickinson
On Dec 8, 2:24 pm, Rasmus Fogh [EMAIL PROTECTED] wrote: So, I would much prefer a language change. I am not competent to even propose one properly, but I'll try. I don't see any technical problems in what you propose: as far as I can see it's entirely feasible. However: should. On the

Re: Rich Comparisons Gotcha

2008-12-09 Thread Rasmus Fogh
Mark Dickinson wrote: On Dec 8, 2:24 pm, Rasmus Fogh [EMAIL PROTECTED] wrote: So, I would much prefer a language change. I am not competent to even propose one properly, but I'll try. I don't see any technical problems in what you propose: as far as I can see it's entirely feasible.

Re: Rich Comparisons Gotcha

2008-12-09 Thread Rhamphoryncus
You grossly overvalue using the in operator on lists. It's far more common to use a dict or set for containment tests, due to O(1) performance rather than O(n). I doubt the numpy array supports hashing, so an error for misuse is all you should expect. In the rare case that you want to test for

Re: Rich Comparisons Gotcha

2008-12-09 Thread Rhodri James
On Mon, 08 Dec 2008 14:24:59 -, Rasmus Fogh [EMAIL PROTECTED] wrote: On the minus side there would be the difference between '__equal__' and '__eq__' to confuse people. This is a very big minus. It would be far better to spell __equal__ in such a way as to make it clear why it wasn't

Re: Rich Comparisons Gotcha

2008-12-08 Thread James Stroud
Robert Kern wrote: James Stroud wrote: I think it skips straight to __eq__ if the element is not the first in the list. No, it doesn't skip straight to __eq__(). y is 1 returns False, so (y==1) is checked. When y is a numpy array, this returns an array of bools. list.__contains__() tries to

Re: Rich Comparisons Gotcha

2008-12-08 Thread Rasmus Fogh
Rober Kern wrote: James Stroud wrote: Steven D'Aprano wrote: On Sun, 07 Dec 2008 13:57:54 -0800, James Stroud wrote: Rasmus Fogh wrote: ll1 = [y,1] y in ll1 True ll2 = [1,y] y in ll2 Traceback (most recent call last): File stdin, line 1, in module ValueError: The truth value of an

Re: Rich Comparisons Gotcha

2008-12-08 Thread Rhamphoryncus
On Dec 7, 4:20 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sun, 07 Dec 2008 15:32:53 -0600, Robert Kern wrote: Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False Blame IEEE

Re: Rich Comparisons Gotcha

2008-12-08 Thread Terry Reedy
Robert Kern wrote: There is an explicit policy that __eq__() methods can return non-bools for various purposes. I consider that policy to a presence that can be removed. There is no check because that policy exists, not the other way around. OK, presence in manual versus presence in code.

Re: Rich Comparisons Gotcha

2008-12-08 Thread Robert Kern
Rhamphoryncus wrote: On Dec 7, 4:20 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sun, 07 Dec 2008 15:32:53 -0600, Robert Kern wrote: Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False

Re: Rich Comparisons Gotcha

2008-12-08 Thread Rhamphoryncus
On Dec 8, 11:54 am, Robert Kern [EMAIL PROTECTED] wrote: Rhamphoryncus wrote: On Dec 7, 4:20 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sun, 07 Dec 2008 15:32:53 -0600, Robert Kern wrote: Rasmus Fogh wrote: Current behaviour is both inconsistent and

Re: Rich Comparisons Gotcha

2008-12-08 Thread Robert Kern
Rhamphoryncus wrote: On Dec 8, 11:54 am, Robert Kern [EMAIL PROTECTED] wrote: Rhamphoryncus wrote: On Dec 7, 4:20 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sun, 07 Dec 2008 15:32:53 -0600, Robert Kern wrote: Rasmus Fogh wrote: Current behaviour is both inconsistent

Re: Rich Comparisons Gotcha

2008-12-08 Thread Rhamphoryncus
On Dec 8, 1:04 pm, Robert Kern [EMAIL PROTECTED] wrote: Rhamphoryncus wrote: On Dec 8, 11:54 am, Robert Kern [EMAIL PROTECTED] wrote: Rhamphoryncus wrote: On Dec 7, 4:20 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sun, 07 Dec 2008 15:32:53 -0600, Robert Kern

Re: Rich Comparisons Gotcha

2008-12-08 Thread Robert Kern
Rhamphoryncus wrote: On Dec 8, 1:04 pm, Robert Kern [EMAIL PROTECTED] wrote: Rhamphoryncus wrote: On Dec 8, 11:54 am, Robert Kern [EMAIL PROTECTED] wrote: Rhamphoryncus wrote: On Dec 7, 4:20 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sun, 07 Dec 2008 15:32:53 -0600,

Re: Rich Comparisons Gotcha

2008-12-08 Thread Terry Reedy
Rasmus Fogh wrote: For my personal problem I could indeed wrap all objects in a wrapper with whatever 'correct' behaviour I want (thanks, TJR). It does seem a bit I was not suggesting that you wrap *everything*, merely an adaptor for numpy arrays in whatever subclass and source it is that

Re: Rich Comparisons Gotcha

2008-12-08 Thread Robert Kern
Terry Reedy wrote: Rasmus Fogh wrote: much, though, just to get code like this to work as intended: alist.append(x) print ('x is present: ', x in alist) Even if rich comparisons as you propose, the above would *still* not necessarily work. Collection classes can define a __contains__

Re: Rich Comparisons Gotcha

2008-12-08 Thread MRAB
Terry Reedy wrote: Rasmus Fogh wrote: For my personal problem I could indeed wrap all objects in a wrapper with whatever 'correct' behaviour I want (thanks, TJR). It does seem a bit I was not suggesting that you wrap *everything*, merely an adaptor for numpy arrays in whatever subclass and

Re: Rich Comparisons Gotcha

2008-12-08 Thread Robert Kern
MRAB wrote: Terry Reedy wrote: Rasmus Fogh wrote: For my personal problem I could indeed wrap all objects in a wrapper with whatever 'correct' behaviour I want (thanks, TJR). It does seem a bit I was not suggesting that you wrap *everything*, merely an adaptor for numpy arrays in whatever

Re: Rich Comparisons Gotcha

2008-12-08 Thread Rhamphoryncus
On Dec 8, 2:51 pm, Robert Kern [EMAIL PROTECTED] wrote: Rhamphoryncus wrote: We've always done it that way is NOT a use case!  Certainly, it's a factor, but it seems quite weak compared to the sort use case. I didn't say it was. I was explaining that sorting was probably *not* a use case

Re: Rich Comparisons Gotcha

2008-12-08 Thread Terry Reedy
Robert Kern wrote: Terry Reedy wrote: Rasmus Fogh wrote: much, though, just to get code like this to work as intended: alist.append(x) print ('x is present: ', x in alist) Even if rich comparisons as you propose, the above would *still* not necessarily work. Collection classes can

Re: Rich Comparisons Gotcha

2008-12-08 Thread Steven D'Aprano
On Mon, 08 Dec 2008 14:24:59 +, Rasmus Fogh wrote: For my personal problem I could indeed wrap all objects in a wrapper with whatever 'correct' behaviour I want (thanks, TJR). It does seem a bit much, though, just to get code like this to work as intended: alist.append(x) print ('x

Re: Rich Comparisons Gotcha

2008-12-08 Thread Steven D'Aprano
On Mon, 08 Dec 2008 10:20:56 -0800, Rhamphoryncus wrote: On Dec 7, 4:20 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sun, 07 Dec 2008 15:32:53 -0600, Robert Kern wrote: Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these

Re: Rich Comparisons Gotcha

2008-12-08 Thread Steven D'Aprano
On Sun, 07 Dec 2008 16:24:58 -0800, George Sakkis wrote: On Dec 7, 6:37 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: ... Given: x = log(-5)  # a NaN y = log(-2)  # the same NaN x == y  # Some people want this to be true for NaNs. Then: # Compare x and y directly.

Re: Rich Comparisons Gotcha

2008-12-08 Thread Rhamphoryncus
On Dec 8, 7:44 pm, Steven D'Aprano [EMAIL PROTECTED] wrote: On Mon, 08 Dec 2008 10:20:56 -0800, Rhamphoryncus wrote: On Dec 7, 4:20 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sun, 07 Dec 2008 15:32:53 -0600, Robert Kern wrote: Rasmus Fogh wrote: Current

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
Rasmus Fogh wrote: Dear All, For the first time I have come across a Python feature that seems completely wrong. After the introduction of rich comparisons, equality comparison does not have to return a truth value, and may indeed return nothing at all and throw an error instead. As a result,

Re: Rich Comparisons Gotcha

2008-12-07 Thread Rasmus Fogh
Robert Kern Wrote: Terry Reedy wrote: Rasmus Fogh wrote: Personally I would like to get these [EMAIL PROTECTED]* misfeatures removed, What you are calling a misfeature is an absence, not a presence that can be removed. That's not quite true. Rich comparisons explicitly allow non-boolean

Re: Rich Comparisons Gotcha

2008-12-07 Thread Rasmus Fogh
Jamed Stroud Wrote: Rasmus Fogh wrote: Dear All, For the first time I have come across a Python feature that seems completely wrong. After the introduction of rich comparisons, equality comparison does not have to return a truth value, and may indeed return nothing at all and throw an error

Re: Rich Comparisons Gotcha

2008-12-07 Thread Luis Zarrabeitia
Quoting James Stroud [EMAIL PROTECTED]: First, here is why the ability to throw an error is a feature: class Apple(object): def __init__(self, appleness): self.appleness = appleness def __cmp__(self, other): assert isinstance(other, Apple), 'must compare apples to

Re: Rich Comparisons Gotcha

2008-12-07 Thread Steven D'Aprano
On Sun, 07 Dec 2008 13:03:43 +, Rasmus Fogh wrote: Jamed Stroud Wrote: ... Second, consider that any value in python also evaluates to a truth value in boolean context. But bool(x) can fail too. So not every object in Python can be interpreted as a truth value. Third, every function

Re: Rich Comparisons Gotcha

2008-12-07 Thread Rasmus Fogh
On Sun, 07 Dec 2008 13:03:43 +, Rasmus Fogh wrote: Jamed Stroud Wrote: ... Second, consider that any value in python also evaluates to a truth value in boolean context. But bool(x) can fail too. So not every object in Python can be interpreted as a truth value. Third, every function

Re: Rich Comparisons Gotcha

2008-12-07 Thread Mark Dickinson
On Dec 7, 4:23 pm, Rasmus Fogh [EMAIL PROTECTED] wrote: If is is possible to change the language, how about having two diferent functions, one for overloading the '==' operator, and another for testing list and set membership, dictionary key identity, etc.? I've often thought that this would

Re: Rich Comparisons Gotcha

2008-12-07 Thread Robert Kern
Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False Blame IEEE for that one. Rich comparisons have nothing to do with that one. ll = [x] x in ll True x == ll[0] False import numpy y = numpy.zeros((3,))

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
Luis Zarrabeitia wrote: Quoting James Stroud [EMAIL PROTECTED]: First, here is why the ability to throw an error is a feature: class Apple(object): def __init__(self, appleness): self.appleness = appleness def __cmp__(self, other): assert isinstance(other, Apple), 'must

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False Perhaps this should raise an exception? I think the problem is not with comparisons in general but with the fact that nan is type float: py

Re: Rich Comparisons Gotcha

2008-12-07 Thread Terry Reedy
Robert Kern wrote: Terry Reedy wrote: Rasmus Fogh wrote: Personally I would like to get these [EMAIL PROTECTED]* misfeatures removed, What you are calling a misfeature is an absence, not a presence that can be removed. That's not quite true. In what way, pray tell. My statement still

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
James Stroud wrote: [cast to bool] for numpy works like a unary ufunc. Scratch that. Not thinking and typing at same time. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com --

Re: Rich Comparisons Gotcha

2008-12-07 Thread Terry Reedy
Rasmus Fogh wrote: Can anybody see a way this could be fixed (please)? I may well have to live with it, but I would really prefer not to. I made a suggestion in my first response, which perhaps you missed. tjr -- http://mail.python.org/mailman/listinfo/python-list

Re: Rich Comparisons Gotcha

2008-12-07 Thread Steven D'Aprano
On Sun, 07 Dec 2008 15:32:53 -0600, Robert Kern wrote: Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False Blame IEEE for that one. Rich comparisons have nothing to do with that one. There is nothing

Re: Re: Rich Comparisons Gotcha

2008-12-07 Thread acerimusdux
James Stroud wrote: div class=moz-text-flowed style=font-family: -moz-fixedRasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False Perhaps this should raise an exception? I think the problem is not with

Re: Rich Comparisons Gotcha

2008-12-07 Thread Steven D'Aprano
On Sun, 07 Dec 2008 23:20:12 +, Steven D'Aprano wrote: On Sun, 07 Dec 2008 15:32:53 -0600, Robert Kern wrote: Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False Blame IEEE for that one. Rich

Re: Rich Comparisons Gotcha

2008-12-07 Thread Steven D'Aprano
On Sun, 07 Dec 2008 13:57:54 -0800, James Stroud wrote: Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False Perhaps this should raise an exception? Why on earth would you want checking equality on NaN to

Re: Rich Comparisons Gotcha

2008-12-07 Thread Robert Kern
Steven D'Aprano wrote: On Sun, 07 Dec 2008 23:20:12 +, Steven D'Aprano wrote: On Sun, 07 Dec 2008 15:32:53 -0600, Robert Kern wrote: Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these examples show. x = float('NaN') x == x False Blame IEEE for

Re: Rich Comparisons Gotcha

2008-12-07 Thread George Sakkis
On Dec 7, 6:37 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sun, 07 Dec 2008 23:20:12 +, Steven D'Aprano wrote: On Sun, 07 Dec 2008 15:32:53 -0600, Robert Kern wrote: Rasmus Fogh wrote: Current behaviour is both inconsistent and counterintuitive, as these

Re: Rich Comparisons Gotcha

2008-12-07 Thread Robert Kern
Terry Reedy wrote: Robert Kern wrote: Terry Reedy wrote: Rasmus Fogh wrote: Personally I would like to get these [EMAIL PROTECTED]* misfeatures removed, What you are calling a misfeature is an absence, not a presence that can be removed. That's not quite true. In what way, pray tell.

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
Steven D'Aprano wrote: On Sun, 07 Dec 2008 13:57:54 -0800, James Stroud wrote: Rasmus Fogh wrote: ll1 = [y,1] y in ll1 True ll2 = [1,y] y in ll2 Traceback (most recent call last): File stdin, line 1, in module ValueError: The truth value of an array with more than one element is

Re: Rich Comparisons Gotcha

2008-12-07 Thread Robert Kern
James Stroud wrote: Steven D'Aprano wrote: On Sun, 07 Dec 2008 13:57:54 -0800, James Stroud wrote: Rasmus Fogh wrote: ll1 = [y,1] y in ll1 True ll2 = [1,y] y in ll2 Traceback (most recent call last): File stdin, line 1, in module ValueError: The truth value of an array with more than

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
Robert Kern wrote: James Stroud wrote: I'm missing how a.all() solves the problem Rasmus describes, namely that the order of a python *list* affects the results of containment tests by numpy.array. E.g. y in ll1 and y in ll2 evaluate to different results in his example. It still seems like a

Re: Rich Comparisons Gotcha

2008-12-07 Thread Steven D'Aprano
On Sun, 07 Dec 2008 16:23:59 +, Rasmus Fogh wrote: Just to keep you from shooting at straw men: I would have liked it to be part of the design contract (a convention, if you like) that 1) bool(x == y) should return a boolean and never throw an error Can't be done without making bool

Re: Rich Comparisons Gotcha

2008-12-07 Thread Robert Kern
James Stroud wrote: Robert Kern wrote: James Stroud wrote: I'm missing how a.all() solves the problem Rasmus describes, namely that the order of a python *list* affects the results of containment tests by numpy.array. E.g. y in ll1 and y in ll2 evaluate to different results in his example.

Re: Rich Comparisons Gotcha

2008-12-07 Thread James Stroud
Robert Kern wrote: James Stroud wrote: py 112 = [1, y] py y in 112 Traceback (most recent call last): File stdin, line 1, in module ValueError: The truth value of an array with more than one element is... but not py ll1 = [y,1] py y in ll1 True It's this discrepancy that seems like a bug,

Re: Rich Comparisons Gotcha

2008-12-07 Thread Robert Kern
James Stroud wrote: Robert Kern wrote: James Stroud wrote: py 112 = [1, y] py y in 112 Traceback (most recent call last): File stdin, line 1, in module ValueError: The truth value of an array with more than one element is... but not py ll1 = [y,1] py y in ll1 True It's this discrepancy

Rich Comparisons Gotcha

2008-12-06 Thread Rasmus Fogh
Dear All, For the first time I have come across a Python feature that seems completely wrong. After the introduction of rich comparisons, equality comparison does not have to return a truth value, and may indeed return nothing at all and throw an error instead. As a result, code like if foo ==

Re: Rich Comparisons Gotcha

2008-12-06 Thread Terry Reedy
Rasmus Fogh wrote: Dear All, For the first time I have come across a Python feature that seems completely wrong. After the introduction of rich comparisons, equality comparison does not have to return a truth value, and may indeed return nothing at all and throw an error instead. As a result,

Re: Rich Comparisons Gotcha

2008-12-06 Thread Robert Kern
Terry Reedy wrote: Rasmus Fogh wrote: Dear All, For the first time I have come across a Python feature that seems completely wrong. After the introduction of rich comparisons, equality comparison does not have to return a truth value, and may indeed return nothing at all and throw an error