Skip to content

Commit 29b4b58

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

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pandas/types/common.py

+29
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@
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+
Examples
47+
--------
48+
>>> arr = np.array([1, 2, 3], dtype=np.int64)
49+
>>> arr
50+
array([1, 2, 3])
51+
>>>
52+
>>> arr.dtype
53+
dtype('int64')
54+
>>>
55+
>>> float_arr = _ensure_float(arr)
56+
>>> float_arr
57+
array([ 1., 2., 3.])
58+
>>>
59+
>>> float_arr.dtype
60+
dtype('float64')
61+
"""
62+
3463
if issubclass(arr.dtype.type, (np.integer, np.bool_)):
3564
arr = arr.astype(float)
3665
return arr

0 commit comments

Comments
 (0)