Skip to content

Commit 4064f7a

Browse files
committed
BUG: remove part of error handler pandas-dev#40729
1 parent 64f0844 commit 4064f7a

File tree

3 files changed

+8
-30
lines changed

3 files changed

+8
-30
lines changed

pandas/core/arrays/floating.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,7 @@ def coerce_to_array(
134134
return values, mask
135135

136136
values = np.array(values, copy=copy)
137-
if is_object_dtype(values):
138-
inferred_type = lib.infer_dtype(values, skipna=True)
139-
if inferred_type == "empty":
140-
values = np.empty(len(values))
141-
values.fill(np.nan)
142-
elif inferred_type not in [
143-
"floating",
144-
"integer",
145-
"mixed-integer",
146-
"integer-na",
147-
"mixed-integer-float",
148-
]:
149-
raise TypeError(f"{values.dtype} cannot be converted to a FloatingDtype")
150-
151-
elif is_bool_dtype(values) and is_float_dtype(dtype):
137+
if is_bool_dtype(values) and is_float_dtype(dtype):
152138
values = np.array(values, dtype=float, copy=copy)
153139

154140
elif not (is_integer_dtype(values) or is_float_dtype(values)):

pandas/core/arrays/integer.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,7 @@ def coerce_to_array(
190190
return values, mask
191191

192192
values = np.array(values, copy=copy)
193-
if is_object_dtype(values):
194-
inferred_type = lib.infer_dtype(values, skipna=True)
195-
if inferred_type == "empty":
196-
values = np.empty(len(values))
197-
values.fill(np.nan)
198-
elif inferred_type not in [
199-
"floating",
200-
"integer",
201-
"mixed-integer",
202-
"integer-na",
203-
"mixed-integer-float",
204-
]:
205-
raise TypeError(f"{values.dtype} cannot be converted to an IntegerDtype")
206-
207-
elif is_bool_dtype(values) and is_integer_dtype(dtype):
193+
if is_bool_dtype(values) and is_integer_dtype(dtype):
208194
values = np.array(values, dtype=int, copy=copy)
209195

210196
elif not (is_integer_dtype(values) or is_float_dtype(values)):

pandas/tests/arrays/string_/test_string.py

+6
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ def test_astype_int(dtype, request):
363363
expected = pd.array([1, pd.NA, 3], dtype="Int64")
364364
tm.assert_extension_array_equal(result, expected)
365365

366+
result = pd.Series(['1', '2', '3', '4'], dtype="Int64")
367+
expected = pd.Series([1, 2, 3, 4], dtype="Int64")
368+
tm.assert_series_equal(result, expected)
366369

367370
def test_astype_float(dtype, any_float_allowed_nullable_dtype, request):
368371
# Don't compare arrays (37974)
@@ -383,6 +386,9 @@ def test_astype_float(dtype, any_float_allowed_nullable_dtype, request):
383386
expected = pd.Series([1.1, np.nan, 3.3], dtype=any_float_allowed_nullable_dtype)
384387
tm.assert_series_equal(result, expected)
385388

389+
result = pd.Series(['1', '2', '3', '4'], dtype="Float64")
390+
expected = pd.Series([1, 2, 3, 4], dtype="Float64")
391+
tm.assert_series_equal(result, expected)
386392

387393
@pytest.mark.parametrize("skipna", [True, False])
388394
@pytest.mark.xfail(reason="Not implemented StringArray.sum")

0 commit comments

Comments
 (0)