@@ -2357,34 +2357,30 @@ def test_clip_property(self, data, arr):
23572357 That accounts for most of the function; the actual test is just three
23582358 lines to calculate and compare actual vs expected results!
23592359 """
2360+ numeric_dtypes = hynp .integer_dtypes () | hynp .floating_dtypes ()
23602361 # Generate shapes for the bounds which can be broadcast with each other
23612362 # and with the base shape. Below, we might decide to use scalar bounds,
23622363 # but it's clearer to generate these shapes unconditionally in advance.
23632364 in_shapes , result_shape = data .draw (
23642365 hynp .mutually_broadcastable_shapes (
2365- num_shapes = 2 ,
2366- base_shape = arr .shape ,
2367- # Commenting out the min_dims line allows zero-dimensional arrays,
2368- # and zero-dimensional arrays containing NaN make the test fail.
2369- min_dims = 1
2366+ num_shapes = 2 , base_shape = arr .shape
23702367 )
23712368 )
2372- # This test can fail if we allow either bound to be a scalar `nan`, or
2373- # if bounds are of a different (still integer or float) dtype than the
2374- # array. At some point we should investigate and fix those problems.
2375- amin = data .draw (
2376- hynp .from_dtype (arr .dtype , allow_nan = False )
2377- | hynp .arrays (dtype = arr .dtype , shape = in_shapes [0 ])
2378- )
2379- amax = data .draw (
2380- hynp .from_dtype (arr .dtype , allow_nan = False )
2381- | hynp .arrays (dtype = arr .dtype , shape = in_shapes [1 ])
2382- )
2369+ # Scalar `nan` is deprecated due to the differing behaviour it shows.
2370+ s = numeric_dtypes .flatmap (
2371+ lambda x : hynp .from_dtype (x , allow_nan = False ))
2372+ amin = data .draw (s | hynp .arrays (dtype = numeric_dtypes ,
2373+ shape = in_shapes [0 ], elements = {"allow_nan" : False }))
2374+ amax = data .draw (s | hynp .arrays (dtype = numeric_dtypes ,
2375+ shape = in_shapes [1 ], elements = {"allow_nan" : False }))
23832376
23842377 # Then calculate our result and expected result and check that they're
2385- # equal! See gh-12519 for discussion deciding on this property.
2378+ # equal! See gh-12519 and gh-19457 for discussion deciding on this
2379+ # property and the result_type argument.
23862380 result = np .clip (arr , amin , amax )
2387- expected = np .minimum (amax , np .maximum (arr , amin ))
2381+ t = np .result_type (arr , amin , amax )
2382+ expected = np .minimum (amax , np .maximum (arr , amin , dtype = t ), dtype = t )
2383+ assert result .dtype == t
23882384 assert_array_equal (result , expected )
23892385
23902386
0 commit comments