|
8 | 8 | import platform
|
9 | 9 | import re
|
10 | 10 | import sys
|
| 11 | +import decimal |
| 12 | +from io import TextIOWrapper |
11 | 13 |
|
12 | 14 | import numpy as np
|
13 | 15 | import pytest
|
|
23 | 25 | from pandas.io.common import URLError
|
24 | 26 | from pandas.io.parsers import TextFileReader, TextParser
|
25 | 27 | from pandas.core.arrays.integer import Int64Dtype
|
| 28 | +from pandas.tests.extension.decimal import DecimalDtype |
26 | 29 |
|
27 | 30 |
|
28 | 31 | class ParserTests(object):
|
@@ -1630,13 +1633,23 @@ def test_buffer_rd_bytes_bad_unicode(self):
|
1630 | 1633 |
|
1631 | 1634 | def test_EA_types(self):
|
1632 | 1635 | df = pd.DataFrame({'Int': pd.Series([1, 2, 3], dtype='Int64'),
|
1633 |
| - 'A': [1, 2, 1]}) |
| 1636 | + 'A': pd.Series([1, 2, 1], dtype=Int64Dtype)}) |
1634 | 1637 | data = df.to_csv(index=False)
|
1635 |
| - result = pd.read_csv(StringIO(data), dtype={'Int': Int64Dtype}) |
1636 |
| - assert result is not None |
| 1638 | + result = pd.read_csv(StringIO(data), dtype={'Int': 'Int64', |
| 1639 | + 'A': Int64Dtype}) |
| 1640 | + tm.assert_frame_equal(df, result) |
1637 | 1641 |
|
1638 | 1642 | df = pd.DataFrame({'Int': pd.Series([1, 2, 3], dtype='Int8'),
|
1639 | 1643 | 'A': [1, 2, 1]})
|
1640 | 1644 | data = df.to_csv(index=False)
|
1641 | 1645 | result = pd.read_csv(StringIO(data), dtype={'Int': 'Int8'})
|
1642 |
| - assert result is not None |
| 1646 | + tm.assert_frame_equal(df, result) |
| 1647 | + |
| 1648 | + df = pd.DataFrame({'Dec': pd.Series([decimal.Decimal('1.234'), |
| 1649 | + decimal.Decimal('2.123'), |
| 1650 | + decimal.Decimal('4.521')], |
| 1651 | + dtype=DecimalDtype), |
| 1652 | + 'A': [1, 2, 1]}) |
| 1653 | + data = df.to_csv(index=False) |
| 1654 | + result = pd.read_csv(StringIO(data), dtype={'Dec': DecimalDtype}) |
| 1655 | + tm.assert_frame_equal(df, result) |
0 commit comments