Skip to content

Commit d624031

Browse files
committed
DOC: document pandas.types.common
Closes pandas-devgh-15895.
1 parent d9e00d2 commit d624031

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pandas/types/common.py

+26
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@
3131

3232

3333
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+
3447
if issubclass(arr.dtype.type, (np.integer, np.bool_)):
3548
arr = arr.astype(float)
3649
return arr
@@ -46,6 +59,19 @@ def _ensure_float(arr):
4659

4760

4861
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+
4975
if not is_categorical(arr):
5076
from pandas import Categorical
5177
arr = Categorical(arr)

0 commit comments

Comments
 (0)