Skip to content

Commit df03111

Browse files
committed
CLN: remove coerce_float keyword from construction.internals
1 parent d0db009 commit df03111

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

pandas/core/frame.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,11 @@ def from_records(
18521852
columns = ensure_index(columns)
18531853
arr_columns = columns
18541854
else:
1855-
arrays, arr_columns = to_arrays(data, columns, coerce_float=coerce_float)
1855+
arrays, arr_columns = to_arrays(data, columns)
1856+
if coerce_float:
1857+
for i, arr in enumerate(arrays):
1858+
if arr.dtype == object:
1859+
arrays[i] = lib.maybe_convert_objects(arr, try_float=True)
18561860

18571861
arr_columns = ensure_index(arr_columns)
18581862
if columns is not None:

pandas/core/internals/construction.py

+10-21
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,7 @@ def dataclasses_to_dicts(data):
499499
# Conversion of Inputs to Arrays
500500

501501

502-
def to_arrays(
503-
data, columns, coerce_float: bool = False, dtype: Optional[DtypeObj] = None
504-
):
502+
def to_arrays(data, columns, dtype: Optional[DtypeObj] = None):
505503
"""
506504
Return list of arrays, columns.
507505
"""
@@ -525,15 +523,11 @@ def to_arrays(
525523
return [[]] * len(columns), columns
526524
return [], [] # columns if columns is not None else []
527525
if isinstance(data[0], (list, tuple)):
528-
return _list_to_arrays(data, columns, coerce_float=coerce_float, dtype=dtype)
526+
return _list_to_arrays(data, columns, dtype=dtype)
529527
elif isinstance(data[0], abc.Mapping):
530-
return _list_of_dict_to_arrays(
531-
data, columns, coerce_float=coerce_float, dtype=dtype
532-
)
528+
return _list_of_dict_to_arrays(data, columns, dtype=dtype)
533529
elif isinstance(data[0], ABCSeries):
534-
return _list_of_series_to_arrays(
535-
data, columns, coerce_float=coerce_float, dtype=dtype
536-
)
530+
return _list_of_series_to_arrays(data, columns, dtype=dtype)
537531
elif isinstance(data[0], Categorical):
538532
if columns is None:
539533
columns = ibase.default_index(len(data))
@@ -549,13 +543,12 @@ def to_arrays(
549543
else:
550544
# last ditch effort
551545
data = [tuple(x) for x in data]
552-
return _list_to_arrays(data, columns, coerce_float=coerce_float, dtype=dtype)
546+
return _list_to_arrays(data, columns, dtype=dtype)
553547

554548

555549
def _list_to_arrays(
556550
data: List[Scalar],
557551
columns: Union[Index, List],
558-
coerce_float: bool = False,
559552
dtype: Optional[DtypeObj] = None,
560553
) -> Tuple[List[Scalar], Union[Index, List[Axis]]]:
561554
if len(data) > 0 and isinstance(data[0], tuple):
@@ -566,7 +559,7 @@ def _list_to_arrays(
566559
# gh-26429 do not raise user-facing AssertionError
567560
try:
568561
columns = _validate_or_indexify_columns(content, columns)
569-
result = _convert_object_array(content, dtype=dtype, coerce_float=coerce_float)
562+
result = _convert_object_array(content, dtype=dtype)
570563
except AssertionError as e:
571564
raise ValueError(e) from e
572565
return result, columns
@@ -575,7 +568,6 @@ def _list_to_arrays(
575568
def _list_of_series_to_arrays(
576569
data: List,
577570
columns: Union[Index, List],
578-
coerce_float: bool = False,
579571
dtype: Optional[DtypeObj] = None,
580572
) -> Tuple[List[Scalar], Union[Index, List[Axis]]]:
581573
if columns is None:
@@ -604,7 +596,7 @@ def _list_of_series_to_arrays(
604596
if values.dtype == np.object_:
605597
content = list(values.T)
606598
columns = _validate_or_indexify_columns(content, columns)
607-
content = _convert_object_array(content, dtype=dtype, coerce_float=coerce_float)
599+
content = _convert_object_array(content, dtype=dtype)
608600
return content, columns
609601
else:
610602
return values.T, columns
@@ -613,7 +605,6 @@ def _list_of_series_to_arrays(
613605
def _list_of_dict_to_arrays(
614606
data: List[Dict],
615607
columns: Union[Index, List],
616-
coerce_float: bool = False,
617608
dtype: Optional[DtypeObj] = None,
618609
) -> Tuple[List[Scalar], Union[Index, List[Axis]]]:
619610
"""
@@ -629,7 +620,6 @@ def _list_of_dict_to_arrays(
629620
data : iterable
630621
collection of records (OrderedDict, dict)
631622
columns: iterables or None
632-
coerce_float : bool
633623
dtype : np.dtype
634624
635625
Returns
@@ -648,7 +638,7 @@ def _list_of_dict_to_arrays(
648638

649639
content = list(lib.dicts_to_array(data, list(columns)).T)
650640
columns = _validate_or_indexify_columns(content, columns)
651-
content = _convert_object_array(content, dtype=dtype, coerce_float=coerce_float)
641+
content = _convert_object_array(content, dtype=dtype)
652642
return content, columns
653643

654644

@@ -711,15 +701,14 @@ def _validate_or_indexify_columns(
711701

712702

713703
def _convert_object_array(
714-
content: List[Scalar], coerce_float: bool = False, dtype: Optional[DtypeObj] = None
704+
content: List[Scalar], dtype: Optional[DtypeObj] = None
715705
) -> List[Scalar]:
716706
"""
717707
Internal function ot convert object array.
718708
719709
Parameters
720710
----------
721711
content: list of processed data records
722-
coerce_float: bool, to coerce floats or not, default is False
723712
dtype: np.dtype, default is None
724713
725714
Returns
@@ -729,7 +718,7 @@ def _convert_object_array(
729718
# provide soft conversion of object dtypes
730719
def convert(arr):
731720
if dtype != np.dtype("O"):
732-
arr = lib.maybe_convert_objects(arr, try_float=coerce_float)
721+
arr = lib.maybe_convert_objects(arr)
733722
arr = maybe_cast_to_datetime(arr, dtype)
734723
return arr
735724

0 commit comments

Comments
 (0)