[pypy-commit] pypy array-and-nan: Replacing `space.eq_w(...)` by `space.is_true(space.eq(...))` in `compare_arrays` and `index_count_array` in array/interp_array.py in order to handle NaN correctly

Yannick_Jadoul pypy.commits at gmail.com
Mon Dec 30 17:58:38 EST 2019


Author: Yannick Jadoul <yannick.jadoul at belgacom.net>
Branch: array-and-nan
Changeset: r98419:fe5283d50ae4
Date: 2019-12-30 23:57 +0100
http://bitbucket.org/pypy/pypy/changeset/fe5283d50ae4/

Log:	Replacing `space.eq_w(...)` by `space.is_true(space.eq(...))` in
	`compare_arrays` and `index_count_array` in array/interp_array.py in
	order to handle NaN correctly

diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -77,7 +77,7 @@
         w_elem1 = arr1.w_getitem(space, i, integer_instead_of_char=True)
         w_elem2 = arr2.w_getitem(space, i, integer_instead_of_char=True)
         if comp_op == EQ:
-            res = space.eq_w(w_elem1, w_elem2)
+            res = space.is_true(space.eq(w_elem1, w_elem2))
             if not res:
                 return space.w_False
         elif comp_op == NE:
@@ -91,7 +91,7 @@
                 res = space.is_true(space.gt(w_elem1, w_elem2))
             if res:
                 return space.w_True
-            elif not space.eq_w(w_elem1, w_elem2):
+            elif not space.is_true(space.eq(w_elem1, w_elem2)):
                 return space.w_False
         else:
             if comp_op == LE:
@@ -100,7 +100,7 @@
                 res = space.is_true(space.ge(w_elem1, w_elem2))
             if not res:
                 return space.w_False
-            elif not space.eq_w(w_elem1, w_elem2):
+            elif not space.is_true(space.eq(w_elem1, w_elem2)):
                 return space.w_True
     # we have some leftovers
     if comp_op == EQ:
@@ -133,7 +133,7 @@
             tp_item=tp_item, count=count,
             arrclass=arrclass)
         w_item = arr.w_getitem(space, i)
-        if space.eq_w(w_item, w_val):
+        if space.is_true(space.eq(w_item, w_val)):
             if count:
                 cnt += 1
             else:
diff --git a/pypy/module/array/test/test_array.py b/pypy/module/array/test/test_array.py
--- a/pypy/module/array/test/test_array.py
+++ b/pypy/module/array/test/test_array.py
@@ -134,6 +134,18 @@
             assert a[2] == 2.5
             assert len(a) == len(values)
 
+    def test_nan(self):
+        for tc in 'fd':
+            a = self.array(tc, [float('nan')])
+            b = self.array(tc, [float('nan')])
+            assert not a == b
+            assert a != b
+            assert not a > b
+            assert not a >= b
+            assert not a < b
+            assert not a <= b
+            assert a.count(float('nan')) == 0
+
     def test_itemsize(self):
         for t in 'cbB':
             assert(self.array(t).itemsize >= 1)


More information about the pypy-commit mailing list