Skip to content

Commit cc12100

Browse files
committed
TST: str dtype -> IntegerDtype conversions
1 parent 90c00c3 commit cc12100

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Diff for: pandas/tests/arrays/integer/test_construction.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def test_from_dtype_from_float(data):
4444

4545

4646
def test_conversions(data_missing):
47-
4847
# astype to object series
4948
df = pd.DataFrame({"A": data_missing})
5049
result = df["A"].astype("object")
@@ -123,7 +122,6 @@ def test_to_integer_array_none_is_nan(a, b):
123122
"values",
124123
[
125124
["foo", "bar"],
126-
["1", "2"],
127125
"foo",
128126
1,
129127
1.0,
@@ -137,13 +135,14 @@ def test_to_integer_array_error(values):
137135
# error in converting existing arrays to IntegerArrays
138136
msg = (
139137
r"(:?.* cannot be converted to an IntegerDtype)"
138+
r"|(invalid literal for int\(\) with base 10: .*)"
140139
r"|(:?values must be a 1D list-like)"
141140
r"|(Cannot pass scalar)"
142141
)
143142
with pytest.raises((ValueError, TypeError), match=msg):
144143
pd.array(values, dtype="Int64")
145144

146-
with pytest.raises(TypeError, match=msg):
145+
with pytest.raises((ValueError, TypeError), match=msg):
147146
IntegerArray._from_sequence(values)
148147

149148

@@ -181,6 +180,17 @@ def test_to_integer_array_float():
181180
assert result.dtype == Int64Dtype()
182181

183182

183+
def test_to_integer_array_str():
184+
result = IntegerArray._from_sequence(["1", "2"])
185+
expected = pd.array([1, 2], dtype="Int64")
186+
tm.assert_extension_array_equal(result, expected)
187+
188+
with pytest.raises(
189+
ValueError, match=r"invalid literal for int\(\) with base 10: .*"
190+
):
191+
IntegerArray._from_sequence(["1.5", "2.0"])
192+
193+
184194
@pytest.mark.parametrize(
185195
"bool_values, int_values, target_dtype, expected_dtype",
186196
[

0 commit comments

Comments
 (0)