Commits

Maciej Fijalkowski committed 24f7e35

a dumb implementation of isna

Comments (0)

Files changed (3)

pypy/module/micronumpy/__init__.py

         'dot': 'interp_numarray.dot',
         'fromstring': 'interp_support.fromstring',
         'flatiter': 'interp_numarray.W_FlatIterator',
+        'isna': 'interp_numarray.isna',
 
         'True_': 'types.Bool.True',
         'False_': 'types.Bool.False',

pypy/module/micronumpy/interp_numarray.py

     def copy(self, space):
         return self.get_concrete().copy(space)
 
+    def empty_copy(self, space, dtype):
+        shape = self.shape
+        size = 1
+        for elem in shape:
+            size *= elem
+        return W_NDimArray(size, shape[:], dtype, 'C')
+
     def flatten(self, space):
         return self.get_concrete().flatten(space)
 
     __iter__ = interp2app(W_FlatIterator.descr_iter),
 )
 W_FlatIterator.acceptable_as_base_class = False
+
+def isna(space, w_obj):
+    if isinstance(w_obj, BaseArray):
+        arr = w_obj.empty_copy(space,
+                               interp_dtype.get_dtype_cache(space).w_booldtype)
+        arr.fill(space, space.wrap(False))
+        return arr
+    return space.wrap(False)

pypy/module/micronumpy/test/test_numarray.py

         a[a & 1 == 1] = array([8, 9, 10])
         assert (a == [[0, 8], [2, 9], [4, 10]]).all()
 
+    def test_isna(self):
+        from _numpypy import isna, array
+        # XXX for now
+        assert not isna(3)
+        assert (isna(array([1, 2, 3, 4])) == [False, False, False, False]).all()
 
 
 class AppTestSupport(BaseNumpyAppTest):