Skip to content

Commit

Permalink
Update utils.py (#46)
Browse files Browse the repository at this point in the history
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 -----------   
```
  • Loading branch information
ryanskeith authored Jul 26, 2024
1 parent 7ca7c65 commit a4f3933
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mizani/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def get_null_value(x: Any) -> NullType:
import pandas as pd

x0 = next(iter(x))
numeric_types: Sequence[type] = (np.int64, np.float64, int, float, bool)
numeric_types: Sequence[type] = (np.int32, np.int64, np.float64, int, float, bool)

if pdtypes.is_object_dtype(x):
return None
Expand Down

0 comments on commit a4f3933

Please sign in to comment.