Skip to content

Commit 5ba95a1

Browse files
TST: added unitest for read_excel and modified series/test_dtypes for np.nan to empty string (pandas-dev#20377)
1 parent 694849d commit 5ba95a1

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

pandas/tests/io/test_excel.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,35 @@ def test_reader_dtype(self, ext):
361361
with pytest.raises(ValueError):
362362
actual = self.get_exceldf(basename, ext, dtype={'d': 'int64'})
363363

364+
def test_reader_dtype_str(self, ext):
365+
# GH 20377
366+
basename = 'testdtype'
367+
actual = self.get_exceldf(basename, ext)
368+
369+
expected = DataFrame({
370+
'a': [1, 2, 3, 4],
371+
'b': [2.5, 3.5, 4.5, 5.5],
372+
'c': [1, 2, 3, 4],
373+
'd': [1.0, 2.0, np.nan, 4.0]}).reindex(
374+
columns=['a', 'b', 'c', 'd'])
375+
376+
tm.assert_frame_equal(actual, expected)
377+
378+
actual = self.get_exceldf(basename, ext,
379+
dtype={'a': 'float64',
380+
'b': 'float32',
381+
'c': str,
382+
'd': str})
383+
384+
expected['a'] = expected['a'].astype('float64')
385+
expected['b'] = expected['b'].astype('float32')
386+
expected['c'] = ['001', '002', '003', '004']
387+
expected['d'] = ['1', '2', '', '4']
388+
tm.assert_frame_equal(actual, expected)
389+
390+
with pytest.raises(ValueError):
391+
actual = self.get_exceldf(basename, ext, dtype={'d': 'int64'})
392+
364393
def test_reading_all_sheets(self, ext):
365394
# Test reading all sheetnames by setting sheetname to None,
366395
# Ensure a dict is returned.

pandas/tests/series/test_dtypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_astype_datetime64tz(self):
142142
tm.rands(1000)]),
143143
Series([string.digits * 10,
144144
tm.rands(63),
145-
tm.rands(64), nan, 1.0])])
145+
tm.rands(64), '', 1.0])])
146146
def test_astype_str_map(self, dtype, series):
147147
# see gh-4405
148148
result = series.astype(dtype)

0 commit comments

Comments
 (0)