Skip to content

CLN: remove coerce_float keyword from construction.internals #38407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 12, 2020
6 changes: 5 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,11 @@ def from_records(
columns = ensure_index(columns)
arr_columns = columns
else:
arrays, arr_columns = to_arrays(data, columns, coerce_float=coerce_float)
arrays, arr_columns = to_arrays(data, columns)
if coerce_float:
for i, arr in enumerate(arrays):
if arr.dtype == object:
arrays[i] = lib.maybe_convert_objects(arr, try_float=True)

arr_columns = ensure_index(arr_columns)
if columns is not None:
Expand Down
14 changes: 5 additions & 9 deletions pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,7 @@ def dataclasses_to_dicts(data):
# Conversion of Inputs to Arrays


def to_arrays(
data, columns, coerce_float: bool = False, dtype: Optional[DtypeObj] = None
):
def to_arrays(data, columns, dtype: Optional[DtypeObj] = None):
"""
Return list of arrays, columns.
"""
Expand Down Expand Up @@ -548,7 +546,7 @@ def to_arrays(
data = [tuple(x) for x in data]
content, columns = _list_to_arrays(data, columns)

content, columns = _finalize_columns_and_data(content, columns, dtype, coerce_float)
content, columns = _finalize_columns_and_data(content, columns, dtype)
return content, columns


Expand Down Expand Up @@ -635,7 +633,6 @@ def _finalize_columns_and_data(
content: np.ndarray,
columns: Optional[Union[Index, List]],
dtype: Optional[DtypeObj],
coerce_float: bool,
) -> Tuple[List[np.ndarray], Union[Index, List[Axis]]]:
"""
Ensure we have valid columns, cast object dtypes if possible.
Expand All @@ -649,7 +646,7 @@ def _finalize_columns_and_data(
raise ValueError(err) from err

if len(content) and content[0].dtype == np.object_:
content = _convert_object_array(content, dtype=dtype, coerce_float=coerce_float)
content = _convert_object_array(content, dtype=dtype)
return content, columns


Expand Down Expand Up @@ -712,15 +709,14 @@ def _validate_or_indexify_columns(


def _convert_object_array(
content: List[Scalar], coerce_float: bool = False, dtype: Optional[DtypeObj] = None
content: List[Scalar], dtype: Optional[DtypeObj] = None
) -> List[Scalar]:
"""
Internal function ot convert object array.

Parameters
----------
content: list of processed data records
coerce_float: bool, to coerce floats or not, default is False
dtype: np.dtype, default is None

Returns
Expand All @@ -730,7 +726,7 @@ def _convert_object_array(
# provide soft conversion of object dtypes
def convert(arr):
if dtype != np.dtype("O"):
arr = lib.maybe_convert_objects(arr, try_float=coerce_float)
arr = lib.maybe_convert_objects(arr)
arr = maybe_cast_to_datetime(arr, dtype)
return arr

Expand Down