55# ---------------------------------------------------------------------
66# ExcelFile class
77import abc
8- from datetime import MINYEAR , date , datetime , time , timedelta
8+ from datetime import date , datetime , time , timedelta
99from distutils .version import LooseVersion
1010from io import UnsupportedOperation
1111import os
@@ -375,15 +375,14 @@ class ExcelFile(object):
375375
376376 def __init__ (self , io , ** kwds ):
377377
378- err_msg = "Install xlrd >= 0.9 .0 for Excel support"
378+ err_msg = "Install xlrd >= 1.0 .0 for Excel support"
379379
380380 try :
381381 import xlrd
382382 except ImportError :
383383 raise ImportError (err_msg )
384384 else :
385- ver = tuple (map (int , xlrd .__VERSION__ .split ("." )[:2 ]))
386- if ver < (0 , 9 ): # pragma: no cover
385+ if xlrd .__VERSION__ < LooseVersion ("1.0.0" ):
387386 raise ImportError (err_msg +
388387 ". Current version " + xlrd .__VERSION__ )
389388
@@ -515,7 +514,6 @@ def _parse_excel(self,
515514 raise NotImplementedError ("chunksize keyword of read_excel "
516515 "is not implemented" )
517516
518- import xlrd
519517 from xlrd import (xldate , XL_CELL_DATE ,
520518 XL_CELL_ERROR , XL_CELL_BOOLEAN ,
521519 XL_CELL_NUMBER )
@@ -528,36 +526,23 @@ def _parse_cell(cell_contents, cell_typ):
528526
529527 if cell_typ == XL_CELL_DATE :
530528
531- if xlrd_0_9_3 :
532- # Use the newer xlrd datetime handling.
533- try :
534- cell_contents = \
535- xldate .xldate_as_datetime (cell_contents ,
536- epoch1904 )
537- except OverflowError :
538- return cell_contents
539- # Excel doesn't distinguish between dates and time,
540- # so we treat dates on the epoch as times only.
541- # Also, Excel supports 1900 and 1904 epochs.
542- year = (cell_contents .timetuple ())[0 :3 ]
543- if ((not epoch1904 and year == (1899 , 12 , 31 )) or
544- (epoch1904 and year == (1904 , 1 , 1 ))):
545- cell_contents = time (cell_contents .hour ,
546- cell_contents .minute ,
547- cell_contents .second ,
548- cell_contents .microsecond )
549- else :
550- # Use the xlrd <= 0.9.2 date handling.
551- try :
552- dt = xldate .xldate_as_tuple (cell_contents , epoch1904 )
553-
554- except xldate .XLDateTooLarge :
555- return cell_contents
556-
557- if dt [0 ] < MINYEAR :
558- cell_contents = time (* dt [3 :])
559- else :
560- cell_contents = datetime (* dt )
529+ # Use the newer xlrd datetime handling.
530+ try :
531+ cell_contents = xldate .xldate_as_datetime (
532+ cell_contents , epoch1904 )
533+ except OverflowError :
534+ return cell_contents
535+
536+ # Excel doesn't distinguish between dates and time,
537+ # so we treat dates on the epoch as times only.
538+ # Also, Excel supports 1900 and 1904 epochs.
539+ year = (cell_contents .timetuple ())[0 :3 ]
540+ if ((not epoch1904 and year == (1899 , 12 , 31 )) or
541+ (epoch1904 and year == (1904 , 1 , 1 ))):
542+ cell_contents = time (cell_contents .hour ,
543+ cell_contents .minute ,
544+ cell_contents .second ,
545+ cell_contents .microsecond )
561546
562547 elif cell_typ == XL_CELL_ERROR :
563548 cell_contents = np .nan
@@ -571,12 +556,6 @@ def _parse_cell(cell_contents, cell_typ):
571556 cell_contents = val
572557 return cell_contents
573558
574- # xlrd >= 0.9.3 can return datetime objects directly.
575- if LooseVersion (xlrd .__VERSION__ ) >= LooseVersion ("0.9.3" ):
576- xlrd_0_9_3 = True
577- else :
578- xlrd_0_9_3 = False
579-
580559 ret_dict = False
581560
582561 # Keep sheetname to maintain backwards compatibility.
0 commit comments