77 assert_array_equal ,
88 assert_raises ,
99 assert_raises_regex ,
10- suppress_warnings ,
1110)
1211
1312import dpnp
1918 get_float_dtypes ,
2019 get_integer_dtypes ,
2120 has_support_aspect64 ,
21+ numpy_version ,
2222)
2323
2424
@@ -282,9 +282,10 @@ def test_weights(self, density):
282282 assert_dtype_allclose (result_hist , expected_hist )
283283 assert_dtype_allclose (result_edges , expected_edges )
284284
285- def test_integer_weights (self ):
285+ @pytest .mark .parametrize ("dt" , get_integer_dtypes (all_int_types = True ))
286+ def test_integer_weights (self , dt ):
286287 v = numpy .array ([1 , 2 , 2 , 4 ])
287- w = numpy .array ([4 , 3 , 2 , 1 ])
288+ w = numpy .array ([4 , 3 , 2 , 1 ], dtype = dt )
288289
289290 iv = dpnp .array (v )
290291 iw = dpnp .array (w )
@@ -602,19 +603,42 @@ def test_different_bins_amount(self, bins_count):
602603 @pytest .mark .parametrize (
603604 "array" ,
604605 [[1 , 2 , 3 ], [1 , 2 , 2 , 1 , 2 , 4 ], [2 , 2 , 2 , 2 ]],
605- ids = ["[1, 2, 3] " , "[1, 2, 2, 1, 2, 4] " , "[2, 2, 2, 2] " ],
606+ ids = ["size=3 " , "size=6 " , "size=4 " ],
606607 )
607- @pytest .mark .parametrize (
608- "minlength" , [0 , 1 , 3 , 5 ], ids = ["0" , "1" , "3" , "5" ]
609- )
610- def test_bincount_minlength (self , array , minlength ):
608+ @pytest .mark .parametrize ("minlength" , [0 , 1 , 3 , 5 ])
609+ def test_minlength (self , array , minlength ):
611610 np_a = numpy .array (array )
612611 dpnp_a = dpnp .array (array )
613612
614613 expected = numpy .bincount (np_a , minlength = minlength )
615614 result = dpnp .bincount (dpnp_a , minlength = minlength )
616615 assert_allclose (expected , result )
617616
617+ @pytest .mark .filterwarnings ("ignore::DeprecationWarning" )
618+ @pytest .mark .parametrize (
619+ "xp" ,
620+ [
621+ dpnp ,
622+ pytest .param (
623+ numpy ,
624+ marks = pytest .mark .xfail (
625+ numpy_version () < "2.3.0" ,
626+ reason = "numpy deprecates but accepts that" ,
627+ strict = True ,
628+ ),
629+ ),
630+ ],
631+ )
632+ def test_minlength_none (self , xp ):
633+ a = xp .array ([1 , 2 , 3 ])
634+ assert_raises_regex (
635+ TypeError ,
636+ "use 0 instead of None for minlength" ,
637+ xp .bincount ,
638+ a ,
639+ minlength = None ,
640+ )
641+
618642 @pytest .mark .parametrize (
619643 "array" , [[1 , 2 , 2 , 1 , 2 , 4 ]], ids = ["[1, 2, 2, 1, 2, 4]" ]
620644 )
@@ -623,7 +647,7 @@ def test_bincount_minlength(self, array, minlength):
623647 [None , [0.3 , 0.5 , 0.2 , 0.7 , 1.0 , - 0.6 ], [2 , 2 , 2 , 2 , 2 , 2 ]],
624648 ids = ["None" , "[0.3, 0.5, 0.2, 0.7, 1., -0.6]" , "[2, 2, 2, 2, 2, 2]" ],
625649 )
626- def test_bincount_weights (self , array , weights ):
650+ def test_weights (self , array , weights ):
627651 np_a = numpy .array (array )
628652 np_weights = numpy .array (weights ) if weights is not None else weights
629653 dpnp_a = dpnp .array (array )
@@ -633,6 +657,20 @@ def test_bincount_weights(self, array, weights):
633657 result = dpnp .bincount (dpnp_a , weights = dpnp_weights )
634658 assert_allclose (expected , result )
635659
660+ @pytest .mark .parametrize (
661+ "data" ,
662+ [numpy .arange (5 ), 3 , [2 , 1 ]],
663+ ids = ["numpy.ndarray" , "scalar" , "list" ],
664+ )
665+ def test_unsupported_data_weights (self , data ):
666+ # check input array
667+ msg = "An array must be any of supported type"
668+ assert_raises_regex (TypeError , msg , dpnp .bincount , data )
669+
670+ # check array of weights
671+ a = dpnp .ones (5 , dtype = dpnp .int32 )
672+ assert_raises_regex (TypeError , msg , dpnp .bincount , a , weights = data )
673+
636674
637675class TestHistogramDd :
638676 @pytest .mark .usefixtures ("suppress_complex_warning" )
0 commit comments