@@ -128,51 +128,6 @@ def ensure_str(value: Union[bytes, Any]) -> str:
128128 return value
129129
130130
131- def ensure_int_or_float (arr : ArrayLike , copy : bool = False ) -> np .ndarray :
132- """
133- Ensure that an dtype array of some integer dtype
134- has an int64 dtype if possible.
135- If it's not possible, potentially because of overflow,
136- convert the array to float64 instead.
137-
138- Parameters
139- ----------
140- arr : array-like
141- The array whose data type we want to enforce.
142- copy: bool
143- Whether to copy the original array or reuse
144- it in place, if possible.
145-
146- Returns
147- -------
148- out_arr : The input array cast as int64 if
149- possible without overflow.
150- Otherwise the input array cast to float64.
151-
152- Notes
153- -----
154- If the array is explicitly of type uint64 the type
155- will remain unchanged.
156- """
157- # TODO: GH27506 potential bug with ExtensionArrays
158- try :
159- # error: Unexpected keyword argument "casting" for "astype"
160- return arr .astype ("int64" , copy = copy , casting = "safe" ) # type: ignore[call-arg]
161- except TypeError :
162- pass
163- try :
164- # error: Unexpected keyword argument "casting" for "astype"
165- return arr .astype ("uint64" , copy = copy , casting = "safe" ) # type: ignore[call-arg]
166- except TypeError :
167- if is_extension_array_dtype (arr .dtype ):
168- # pandas/core/dtypes/common.py:168: error: Item "ndarray" of
169- # "Union[ExtensionArray, ndarray]" has no attribute "to_numpy" [union-attr]
170- return arr .to_numpy ( # type: ignore[union-attr]
171- dtype = "float64" , na_value = np .nan
172- )
173- return arr .astype ("float64" , copy = copy )
174-
175-
176131def ensure_python_int (value : Union [int , np .integer ]) -> int :
177132 """
178133 Ensure that a value is a python int.
0 commit comments