[Numpy-discussion] NA masks for NumPy are ready to test

Bruce Southey bsouthey at gmail.com
Fri Aug 19 14:37:28 EDT 2011


Hi,
Just some immediate minor observations that are really about trying to
be consistent:

1) Could you keep the display of the NA dtype be the same as the array?
For example, NA dtype is displayed as '<f8' but should be displayed as
'float64' as that is the array dtype.
 >>> a=np.array([[1,2,3,np.NA], [3,4,np.nan,5]])
>>> a
array([[  1.,   2.,   3., NA],
       [  3.,   4.,  nan,   5.]])
>>> a.dtype
dtype('float64')
>>> a.sum()
NA(dtype='<f8')

2) Can the 'skipna' flag be added to the methods?
>>> a.sum(skipna=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'skipna' is an invalid keyword argument for this function
>>> np.sum(a,skipna=True)
nan

3) Can the skipna flag be extended to exclude other non-finite cases like NaN?

4) Assigning a np.NA needs a better error message but the Integer
array case is more informative:
>>> b=np.array([1,2,3,4], dtype=np.float128)
>>> b[0]=np.NA
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: float() argument must be a string or a number

>>> j=np.array([1,2,3])
>>> j
array([1, 2, 3])
>>> j[0]=ina
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string or a number, not 'numpy.NAType'

But it is nice that np.NA 'adjusts' to the insertion array:
>>> b.flags.maskna = True
>>> ana
NA(dtype='<f8')
>>> b[0]=ana
>>> b[0]
NA(dtype='<f16')

5) Different display depending on masked state. That is I think that
'maskna=True' should be displayed always when flags.maskna is True :
>>> j=np.array([1,2,3], dtype=np.int8)
>>> j
array([1, 2, 3], dtype=int8)
>>> j.flags.maskna=True
>>> j
array([1, 2, 3], maskna=True, dtype=int8)
>>> j[0]=np.NA
>>> j
array([NA, 2, 3], dtype=int8) # Ithink it should still display 'maskna=True'.

Bruce



More information about the NumPy-Discussion mailing list