|
14 | 14 | import pandas as pd
|
15 | 15 | import pandas.util.testing as tm
|
16 | 16 | import pandas.util._test_decorators as td
|
17 |
| -from pandas import DataFrame, Index, MultiIndex |
| 17 | +from pandas import DataFrame, Index, MultiIndex, Series |
18 | 18 | from pandas.compat import u, range, map, BytesIO, iteritems, PY36
|
19 | 19 | from pandas.core.config import set_option, get_option
|
20 | 20 | from pandas.io.common import URLError
|
@@ -371,7 +371,34 @@ def test_reader_dtype(self, ext):
|
371 | 371 | tm.assert_frame_equal(actual, expected)
|
372 | 372 |
|
373 | 373 | with pytest.raises(ValueError):
|
374 |
| - actual = self.get_exceldf(basename, ext, dtype={'d': 'int64'}) |
| 374 | + self.get_exceldf(basename, ext, dtype={'d': 'int64'}) |
| 375 | + |
| 376 | + @pytest.mark.parametrize("dtype,expected", [ |
| 377 | + (None, |
| 378 | + DataFrame({ |
| 379 | + "a": [1, 2, 3, 4], |
| 380 | + "b": [2.5, 3.5, 4.5, 5.5], |
| 381 | + "c": [1, 2, 3, 4], |
| 382 | + "d": [1.0, 2.0, np.nan, 4.0] |
| 383 | + })), |
| 384 | + ({"a": "float64", |
| 385 | + "b": "float32", |
| 386 | + "c": str, |
| 387 | + "d": str |
| 388 | + }, |
| 389 | + DataFrame({ |
| 390 | + "a": Series([1, 2, 3, 4], dtype="float64"), |
| 391 | + "b": Series([2.5, 3.5, 4.5, 5.5], dtype="float32"), |
| 392 | + "c": ["001", "002", "003", "004"], |
| 393 | + "d": ["1", "2", np.nan, "4"] |
| 394 | + })), |
| 395 | + ]) |
| 396 | + def test_reader_dtype_str(self, ext, dtype, expected): |
| 397 | + # see gh-20377 |
| 398 | + basename = "testdtype" |
| 399 | + |
| 400 | + actual = self.get_exceldf(basename, ext, dtype=dtype) |
| 401 | + tm.assert_frame_equal(actual, expected) |
375 | 402 |
|
376 | 403 | def test_reading_all_sheets(self, ext):
|
377 | 404 | # Test reading all sheetnames by setting sheetname to None,
|
|
0 commit comments