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 )
@@ -220,10 +246,21 @@ def is_datetime_or_timedelta_dtype(arr_or_dtype):
220
246
221
247
def _is_unorderable_exception (e ):
222
248
"""
223
- return a boolean if we an unorderable exception error message
249
+ Check if the exception raised is an unorderable exception.
250
+
251
+ The error message differs for 3 <= PY <= 3.5 and PY >= 3.6, so
252
+ we need to condition based on Python version.
224
253
225
- These are different error message for PY>=3<=3.5 and PY>=3.6
254
+ Parameters
255
+ ----------
256
+ e : The error message to check.
257
+
258
+ Returns
259
+ -------
260
+ is_orderable_exc : Whether or not the exception raised is an
261
+ unorderable exception.
226
262
"""
263
+
227
264
if PY36 :
228
265
return "'>' not supported between instances of" in str (e )
229
266
0 commit comments