has2k1 / mizani

A scales package for python
https://mizani.readthedocs.io
BSD 3-Clause "New" or "Revised" License
49 stars 14 forks source link

Update utils.py #46

Closed ryanskeith closed 1 month ago

ryanskeith commented 3 months ago

Adding in np.int32, as by default Windows creates np.int32. This caused the test_censor test to fail:

INFO   _________________________________ test_censor _________________________________                                                                                                             
INFO                                                                                                                                                                                               
INFO       def test_censor():                                                                                                                                                                      
INFO           x = np.arange(10)                                                                                                                                                                   
INFO   >       xx = censor(x, (2, 8))                                                                                                                                                              
INFO                                                                                                                                                                                               
INFO   tests\test_bounds.py:29:                                                                                                                                                                    
INFO   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _                                                                                                             
INFO   ..\_test_env\Lib\site-packages\mizani\bounds.py:349: in censor                                                                                                                              
INFO       null = get_null_value(x)                                                                                                                                                                
INFO   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _                                                                                                             
INFO                                                                                                                                                                                               
INFO   x = array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])                                                                                                                                                   
INFO                                                                                                                                                                                               
INFO       def get_null_value(x: Any) -> NullType:                                                                                                                                                 
INFO           """                                                                                                                                                                                 
INFO           Return a Null value for the type of values                                                                                                                                          
INFO           """                                                                                                                                                                                 
INFO           from datetime import datetime, timedelta                                                                                                                                            
INFO                                                                                                                                                                                               
INFO           import pandas as pd                                                                                                                                                                 
INFO                                                                                                                                                                                               
INFO           x0 = next(iter(x))                                                                                                                                                                  
INFO           numeric_types: Sequence[type] = (np.int64, np.float64, int, float, bool)                                                                                                            
INFO                                                                                                                                                                                               
INFO           if pdtypes.is_object_dtype(x):                                                                                                                                                      
INFO               return None                                                                                                                                                                     
INFO           elif isinstance(x0, numeric_types):  # type: ignore                                                                                                                                 
INFO               return float("nan")                                                                                                                                                             
INFO           # pandas types subclass cypthon types, so check                                                                                                                                     
INFO           # for them first                                                                                                                                                                    
INFO           elif isinstance(x0, (pd.Timestamp, pd.Timedelta)):                                                                                                                                  
INFO               return type(x0)("NaT")                                                                                                                                                          
INFO           elif isinstance(x0, (datetime, timedelta)):                                                                                                                                         
INFO               return None                                                                                                                                                                     
INFO           elif isinstance(x0, (np.datetime64, np.timedelta64)):                                                                                                                               
INFO               return type(x0)("NaT")                                                                                                                                                          
INFO           else:                                                                                                                                                                               
INFO   >           raise ValueError(                                                                                                                                                               
INFO                   "Cannot get a null value for type: {}".format(type(x[0]))                                                                                                                   
INFO               )                                                                                                                                                                               
INFO   E           ValueError: Cannot get a null value for type: <class 'numpy.int32'>                                                                                                             
INFO                                                                                                                                                                                               
INFO   ..\_test_env\Lib\site-packages\mizani\utils.py:387: ValueError                                                                                                                              
INFO                                                                                                                                                                                               
INFO   ---------- coverage: platform win32, python 3.11.9-final-0 -----------   
has2k1 commented 1 month ago

Thank you.