Skip to content

Commit 33bd3fa

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

File tree

3 files changed

+11
-36
lines changed

3 files changed

+11
-36
lines changed

pandas/core/arrays/floating.py

+2-20
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
import numpy as np
1212

13-
from pandas._libs import (
14-
lib,
15-
missing as libmissing,
16-
)
13+
from pandas._libs import missing as libmissing
1714
from pandas._typing import (
1815
ArrayLike,
1916
DtypeObj,
@@ -28,7 +25,6 @@
2825
is_float_dtype,
2926
is_integer_dtype,
3027
is_list_like,
31-
is_object_dtype,
3228
pandas_dtype,
3329
)
3430
from pandas.core.dtypes.dtypes import (
@@ -134,21 +130,7 @@ def coerce_to_array(
134130
return values, mask
135131

136132
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):
133+
if is_bool_dtype(values) and is_float_dtype(dtype):
152134
values = np.array(values, dtype=float, copy=copy)
153135

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

pandas/core/arrays/integer.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
is_float_dtype,
3636
is_integer_dtype,
3737
is_list_like,
38-
is_object_dtype,
3938
pandas_dtype,
4039
)
4140
from pandas.core.dtypes.missing import isna
@@ -190,21 +189,7 @@ def coerce_to_array(
190189
return values, mask
191190

192191
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):
192+
if is_bool_dtype(values) and is_integer_dtype(dtype):
208193
values = np.array(values, dtype=int, copy=copy)
209194

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

pandas/tests/arrays/string_/test_string.py

+8
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ 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)
369+
366370

367371
def test_astype_float(dtype, any_float_allowed_nullable_dtype, request):
368372
# Don't compare arrays (37974)
@@ -383,6 +387,10 @@ def test_astype_float(dtype, any_float_allowed_nullable_dtype, request):
383387
expected = pd.Series([1.1, np.nan, 3.3], dtype=any_float_allowed_nullable_dtype)
384388
tm.assert_series_equal(result, expected)
385389

390+
result = pd.Series(["1", "2", "3", "4"], dtype="Float64")
391+
expected = pd.Series([1, 2, 3, 4], dtype="Float64")
392+
tm.assert_series_equal(result, expected)
393+
386394

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

0 commit comments

Comments
 (0)