[issue21873] Tuple comparisons with NaNs are broken

2022-03-24 Thread Andreas Kloeckner
Change by Andreas Kloeckner : -- nosy: +inducer ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue21873] Tuple comparisons with NaNs are broken

2014-06-28 Thread akira
akira added the comment: (a, b) (c, d) is more like: if a != c: return a c ... except CPython behaves (undocumented?) as: b d if a is c or a == c else a c the difference is in the presence of `is` operator (identity comparison instead of `__eq__`). `nan is nan` therefore `b d` is

[issue21873] Tuple comparisons with NaNs are broken

2014-06-27 Thread akira
akira added the comment: It is about equality. `float('nan') != float('nan')` unlike `0 == 0`. From msg221603: If not equal, the sequences are ordered the same as their first differing elements. The result of the expression: `(a, whatever) (b, whatever)` is defined by `a b` if a and b

[issue21873] Tuple comparisons with NaNs are broken

2014-06-27 Thread Raymond Hettinger
Raymond Hettinger added the comment: FWIW, the logic for tuple ordering is a bit weird due to rich comparisons. Each pair of elements is first checked for equality (__eq__). Only if the equality comparison returns False does it call the relevant ordering operations (such as __lt__). The

[issue21873] Tuple comparisons with NaNs are broken

2014-06-26 Thread Mak Nazečić-Andrlon
New submission from Mak Nazečić-Andrlon: While searching for a way to work around the breakage of the Schwartzian transform in Python 3 (and the resulting awkwardness if you wish to use heapq or bisect, which do not yet have a key argument), I thought of the good old IEEE-754 NaN.

[issue21873] Tuple comparisons with NaNs are broken

2014-06-26 Thread R. David Murray
Changes by R. David Murray rdmur...@bitdance.com: -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21873 ___ ___

[issue21873] Tuple comparisons with NaNs are broken

2014-06-26 Thread akira
akira added the comment: Is the issue that: (1, float('nan')) == (1, float('nan')) False but nan = float('nan') (1, nan) == (1, nan) True ? `nan != nan` therefore it might be expected that `(a, nan) != (a, nan)` [1]: The values float('NaN') and Decimal('NaN') are special. The

[issue21873] Tuple comparisons with NaNs are broken

2014-06-26 Thread akira
akira added the comment: btw, pypy3 (986752d005bb) is broken: (1, float('nan')) == (1, float('nan')) True -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21873 ___

[issue21873] Tuple comparisons with NaNs are broken

2014-06-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: Python containers are allowed to let identity-imply-equality (the reflesive property of equality). Dicts, lists, tuples, deques, sets, and frozensets all work this way. So for your purposes, you need to use distinct NaN values rather than reusing a

[issue21873] Tuple comparisons with NaNs are broken

2014-06-26 Thread Mak Nazečić-Andrlon
Mak Nazečić-Andrlon added the comment: The bug is that the comparison should throw a TypeError, but does not (for incomparable A). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21873 ___

[issue21873] Tuple comparisons with NaNs are broken

2014-06-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: Python core containers support the invariant: assert all(x in c for x in c) See also: http://bertrandmeyer.com/2010/02/06/reflexivity-and-other-pillars-of-civilization/ -- assignee: - rhettinger ___

[issue21873] Tuple comparisons with NaNs are broken

2014-06-26 Thread akira
akira added the comment: Python containers are allowed to let identity-imply-equality (the reflesive property of equality). Is it documented somewhere? Dicts, lists, tuples, deques, sets, and frozensets all work this way. Is it CPython specific behaviour? --

[issue21873] Tuple comparisons with NaNs are broken

2014-06-26 Thread Mak Nazečić-Andrlon
Mak Nazečić-Andrlon added the comment: It's not about equality. class A: pass ... (float(nan), A()) (float(nan), A()) False That comparison should throw a TypeError, since NaN NaN is False, in the same way that 0 0 is False here: (0, A()) (0, A()) Traceback (most