Skip to content

Commit bcd4fec

Browse files
committed
TST: read_csv to nullable int dtype (pandas-dev#25472)
1 parent d7b8d9c commit bcd4fec

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Tests dtype specification during parsing
3+
for all of the parsers defined in parsers.py
4+
"""
5+
from io import StringIO
6+
7+
import pytest
8+
9+
import pandas as pd
10+
from pandas import DataFrame
11+
import pandas._testing as tm
12+
from pandas.core.arrays.integer import (
13+
Int8Dtype,
14+
Int16Dtype,
15+
Int32Dtype,
16+
Int64Dtype,
17+
)
18+
19+
20+
@pytest.mark.parametrize(
21+
"dtype",
22+
[
23+
"Int8",
24+
"Int16",
25+
"Int32",
26+
"Int64",
27+
Int8Dtype(),
28+
Int16Dtype(),
29+
Int32Dtype(),
30+
Int64Dtype(),
31+
{"a": "Int8", "b": "Int16", "c": Int32Dtype()},
32+
],
33+
)
34+
def test_integer_dtype(all_parsers, dtype):
35+
# GH 25472
36+
parser = all_parsers
37+
data = """a,b,c
38+
,3,5
39+
1,,6
40+
2,4,"""
41+
a_dtype = dtype["a"] if isinstance(dtype, dict) else dtype
42+
b_dtype = dtype["b"] if isinstance(dtype, dict) else dtype
43+
c_dtype = dtype["c"] if isinstance(dtype, dict) else dtype
44+
expected = DataFrame(
45+
{
46+
"a": pd.array([pd.NA, 1, 2], dtype=a_dtype),
47+
"b": pd.array([3, pd.NA, 4], dtype=b_dtype),
48+
"c": pd.array([5, 6, pd.NA], dtype=c_dtype),
49+
}
50+
)
51+
actual = parser.read_csv(StringIO(data), dtype=dtype)
52+
tm.assert_frame_equal(actual, expected)

0 commit comments

Comments
 (0)