@@ -1310,8 +1310,8 @@ def test_minmax_dtypes(self):
1310
1310
m1 = [1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 ]
1311
1311
xm = masked_array (x , mask = m1 )
1312
1312
xm .set_fill_value (1e+20 )
1313
- float_dtypes = [np .half , np .single , np .double ,
1314
- np .longdouble , np .cfloat , np . cdouble , np .clongdouble ]
1313
+ float_dtypes = [np .float16 , np .float32 , np .float64 , np . longdouble ,
1314
+ np .complex64 , np .complex128 , np .clongdouble ]
1315
1315
for float_dtype in float_dtypes :
1316
1316
assert_equal (masked_array (x , mask = m1 , dtype = float_dtype ).max (),
1317
1317
float_dtype (a10 ))
@@ -1614,6 +1614,23 @@ def test_ne_on_structured(self):
1614
1614
assert_equal (test .mask , [[False , False ], [False , True ]])
1615
1615
assert_ (test .fill_value == True )
1616
1616
1617
+ def test_eq_ne_structured_with_non_masked (self ):
1618
+ a = array ([(1 , 1 ), (2 , 2 ), (3 , 4 )],
1619
+ mask = [(0 , 1 ), (0 , 0 ), (1 , 1 )], dtype = 'i4,i4' )
1620
+ eq = a == a .data
1621
+ ne = a .data != a
1622
+ # Test the obvious.
1623
+ assert_ (np .all (eq ))
1624
+ assert_ (not np .any (ne ))
1625
+ # Expect the mask set only for items with all fields masked.
1626
+ expected_mask = a .mask == np .ones ((), a .mask .dtype )
1627
+ assert_array_equal (eq .mask , expected_mask )
1628
+ assert_array_equal (ne .mask , expected_mask )
1629
+ # The masked element will indicated not equal, because the
1630
+ # masks did not match.
1631
+ assert_equal (eq .data , [True , True , False ])
1632
+ assert_array_equal (eq .data , ~ ne .data )
1633
+
1617
1634
def test_eq_ne_structured_extra (self ):
1618
1635
# ensure simple examples are symmetric and make sense.
1619
1636
# from https://github.com/numpy/numpy/pull/8590#discussion_r101126465
@@ -1745,6 +1762,23 @@ def test_eq_for_numeric(self, dt1, dt2, fill):
1745
1762
assert_equal (test .mask , [True , False ])
1746
1763
assert_ (test .fill_value == True )
1747
1764
1765
+ @pytest .mark .parametrize ("op" , [operator .eq , operator .lt ])
1766
+ def test_eq_broadcast_with_unmasked (self , op ):
1767
+ a = array ([0 , 1 ], mask = [0 , 1 ])
1768
+ b = np .arange (10 ).reshape (5 , 2 )
1769
+ result = op (a , b )
1770
+ assert_ (result .mask .shape == b .shape )
1771
+ assert_equal (result .mask , np .zeros (b .shape , bool ) | a .mask )
1772
+
1773
+ @pytest .mark .parametrize ("op" , [operator .eq , operator .gt ])
1774
+ def test_comp_no_mask_not_broadcast (self , op ):
1775
+ # Regression test for failing doctest in MaskedArray.nonzero
1776
+ # after gh-24556.
1777
+ a = array ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]])
1778
+ result = op (a , 3 )
1779
+ assert_ (not result .mask .shape )
1780
+ assert_ (result .mask is nomask )
1781
+
1748
1782
@pytest .mark .parametrize ('dt1' , num_dts , ids = num_ids )
1749
1783
@pytest .mark .parametrize ('dt2' , num_dts , ids = num_ids )
1750
1784
@pytest .mark .parametrize ('fill' , [None , 1 ])
@@ -3444,7 +3478,7 @@ def test_ravel_order(self, order, data_order):
3444
3478
raveled = x .ravel (order )
3445
3479
assert (raveled .filled (0 ) == 0 ).all ()
3446
3480
3447
- # NOTE: Can be wrong if arr order is neither C nor F and `order="K"`
3481
+ # NOTE: Can be wrong if arr order is neither C nor F and `order="K"`
3448
3482
assert_array_equal (arr .ravel (order ), x .ravel (order )._data )
3449
3483
3450
3484
def test_reshape (self ):
0 commit comments