Skip to content

Commit 0b35ec0

Browse files
Dr-Irvroberthdevries
authored andcommitted
BUG: Fix for convert_dtypes with mix of int and string (pandas-dev#32126)
1 parent 2aa87cc commit 0b35ec0

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

Diff for: doc/source/whatsnew/v1.0.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Bug fixes
4545

4646
- Fix bug in :meth:`DataFrame.convert_dtypes` for columns that were already using the ``"string"`` dtype (:issue:`31731`).
4747
- Fixed bug in setting values using a slice indexer with string dtype (:issue:`31772`)
48+
- Fix bug in :meth:`Series.convert_dtypes` for series with mix of integers and strings (:issue:`32117`)
4849

4950
.. ---------------------------------------------------------------------------
5051

Diff for: pandas/core/dtypes/cast.py

-5
Original file line numberDiff line numberDiff line change
@@ -1062,11 +1062,6 @@ def convert_dtypes(
10621062
if convert_integer:
10631063
target_int_dtype = "Int64"
10641064

1065-
if isinstance(inferred_dtype, str) and (
1066-
inferred_dtype == "mixed-integer"
1067-
or inferred_dtype == "mixed-integer-float"
1068-
):
1069-
inferred_dtype = target_int_dtype
10701065
if is_integer_dtype(input_array.dtype) and not is_extension_array_dtype(
10711066
input_array.dtype
10721067
):

Diff for: pandas/tests/series/methods/test_convert_dtypes.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ class TestSeriesConvertDtypes:
8181
),
8282
},
8383
),
84+
( # GH32117
85+
["h", "i", 1],
86+
np.dtype("O"),
87+
{
88+
(
89+
(True, False),
90+
(True, False),
91+
(True, False),
92+
(True, False),
93+
): np.dtype("O"),
94+
},
95+
),
8496
(
8597
[10, np.nan, 20],
8698
np.dtype("float"),
@@ -144,11 +156,23 @@ class TestSeriesConvertDtypes:
144156
[1, 2.0],
145157
object,
146158
{
147-
((True, False), (True, False), (True,), (True, False)): "Int64",
159+
((True,), (True, False), (True,), (True, False)): "Int64",
148160
((True,), (True, False), (False,), (True, False)): np.dtype(
149161
"float"
150162
),
151-
((False,), (True, False), (False,), (True, False)): np.dtype(
163+
((False,), (True, False), (True, False), (True, False)): np.dtype(
164+
"object"
165+
),
166+
},
167+
),
168+
(
169+
[1, 2.5],
170+
object,
171+
{
172+
((True,), (True, False), (True, False), (True, False)): np.dtype(
173+
"float"
174+
),
175+
((False,), (True, False), (True, False), (True, False)): np.dtype(
152176
"object"
153177
),
154178
},

0 commit comments

Comments
 (0)