File tree Expand file tree Collapse file tree 1 file changed +0
-31
lines changed Expand file tree Collapse file tree 1 file changed +0
-31
lines changed Original file line number Diff line number Diff line change 11# avoid deprecation warnings in numpy >= 2.0 
2- from  dataclasses  import  dataclass 
3- from  importlib .metadata  import  version 
4- from  typing  import  Literal , TypeAlias 
52
63import  numpy  as  np 
7- from  packaging .version  import  Version 
84
95if  hasattr (np , "trapezoid" ):
106    # np.trapz is deprecated in numpy 2.0 in favor of np.trapezoid 
117    trapezoid  =  np .trapezoid 
128else :
139    trapezoid  =  np .trapz   # type: ignore # noqa: NPY201 
14- 
15- 
16- NUMPY_VERSION  =  Version (version ("numpy" ))
17- 
18- # list functions that gained support for a copy kwarg at some point since 
19- # our oldest supported numpy version was introduced, and record when that 
20- # support was added 
21- CopyFunc : TypeAlias  =  Literal ["reshape" ]
22- MIN_NUMPY_VERSION : dict [CopyFunc , Version ] =  {
23-     "reshape" : Version ("2.1.0" ),
24- }
25- 
26- 
27- @dataclass (frozen = True , slots = True ) 
28- class  CopyKwarg :
29-     value : bool  |  None 
30- 
31-     def  get (self , f : CopyFunc , / ) ->  dict [Literal ["copy" ], bool  |  None ]:
32-         if  NUMPY_VERSION  >=  MIN_NUMPY_VERSION [f ]:
33-             return  {"copy" : self .value }
34-         else :
35-             return  {}
36- 
37- 
38- COPY_NONE  =  CopyKwarg (None )
39- COPY_TRUE  =  CopyKwarg (True )
40- COPY_FALSE  =  CopyKwarg (False )
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments