@@ -484,9 +484,20 @@ def test_signature_dtype_type(self):
484
484
np .add (3 , 4 , signature = (float_dtype , float_dtype , None ))
485
485
486
486
@pytest .mark .parametrize ("get_kwarg" , [
487
- param (lambda x : {"dtype" : x }, id = "dtype" ),
488
- param (lambda x : {"signature" : (x , None , None )}, id = "signature" )])
487
+ param (lambda dt : {"dtype" : dt }, id = "dtype" ),
488
+ param (lambda dt : {"signature" : (dt , None , None )}, id = "signature" )])
489
489
def test_signature_dtype_instances_allowed (self , get_kwarg ):
490
+ # We allow certain dtype instances when there is a clear singleton
491
+ # and the given one is equivalent; mainly for backcompat.
492
+ int64 = np .dtype ("int64" )
493
+ int64_2 = pickle .loads (pickle .dumps (int64 ))
494
+ # Relies on pickling behavior, if assert fails just remove test...
495
+ assert int64 is not int64_2
496
+
497
+ assert np .add (1 , 2 , ** get_kwarg (int64_2 )).dtype == int64
498
+ td = np .timedelta (2 , "s" )
499
+ assert np .add (td , td , ** get_kwarg ("m8" )).dtype == "m8[s]"
500
+
490
501
msg = "The `dtype` and `signature` arguments to ufuncs"
491
502
492
503
with pytest .raises (TypeError , match = msg ):
0 commit comments