File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 31
31
32
32
33
33
def _ensure_float (arr ):
34
+ """
35
+ Ensure that an array object has a float dtype if possible.
36
+
37
+ Parameters
38
+ ----------
39
+ arr : The array whose data type we want to enforce as float.
40
+
41
+ Returns
42
+ -------
43
+ float_arr : The original array cast to the float dtype if
44
+ possible. Otherwise, the original array is returned.
45
+ """
46
+
34
47
if issubclass (arr .dtype .type , (np .integer , np .bool_ )):
35
48
arr = arr .astype (float )
36
49
return arr
@@ -46,6 +59,19 @@ def _ensure_float(arr):
46
59
47
60
48
61
def _ensure_categorical (arr ):
62
+ """
63
+ Ensure that an array object is a Categorical (if not already).
64
+
65
+ Parameters
66
+ ----------
67
+ arr : The array that we want to convert into a Categorical.
68
+
69
+ Returns
70
+ -------
71
+ cat_arr : The original array cast as a Categorical. If it already
72
+ is a Categorical, we return as is.
73
+ """
74
+
49
75
if not is_categorical (arr ):
50
76
from pandas import Categorical
51
77
arr = Categorical (arr )
You can’t perform that action at this time.
0 commit comments