@@ -361,6 +361,35 @@ def test_reader_dtype(self, ext):
361
361
with pytest .raises (ValueError ):
362
362
actual = self .get_exceldf (basename , ext , dtype = {'d' : 'int64' })
363
363
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
+
364
393
def test_reading_all_sheets (self , ext ):
365
394
# Test reading all sheetnames by setting sheetname to None,
366
395
# Ensure a dict is returned.
0 commit comments