Skip to content

Commit 0638775

Browse files
committed
remove old refs to < 1.0.0
1 parent 19f6981 commit 0638775

File tree

3 files changed

+33
-70
lines changed

3 files changed

+33
-70
lines changed

doc/source/install.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ Optional Dependencies
269269
* `matplotlib <http://matplotlib.org/>`__: for plotting, Version 2.0.0 or higher.
270270
* For Excel I/O:
271271

272-
* `xlrd/xlwt <http://www.python-excel.org/>`__: Excel reading (xlrd) and writing (xlwt)
272+
* `xlrd/xlwt <http://www.python-excel.org/>`__: Excel reading (xlrd), version 1.0.0 or higher required, and writing (xlwt)
273273
* `openpyxl <https://openpyxl.readthedocs.io/en/stable/>`__: openpyxl version 2.4.0
274274
for writing .xlsx files (xlrd >= 0.9.0)
275275
* `XlsxWriter <https://pypi.org/project/XlsxWriter>`__: Alternative Excel writer

pandas/io/excel.py

+20-41
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# ---------------------------------------------------------------------
66
# ExcelFile class
77
import abc
8-
from datetime import MINYEAR, date, datetime, time, timedelta
8+
from datetime import date, datetime, time, timedelta
99
from distutils.version import LooseVersion
1010
from io import UnsupportedOperation
1111
import 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.

pandas/tests/io/test_excel.py

+12-28
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
_mixed_frame['foo'] = 'bar'
3737

3838

39-
@td.skip_if_no('xlrd', '0.9')
39+
@td.skip_if_no('xlrd', '1.0.0')
4040
class SharedItems(object):
4141

4242
@pytest.fixture(autouse=True)
@@ -796,35 +796,19 @@ def tdf(col_sheet_name):
796796
tm.assert_frame_equal(dfs[s], dfs_returned[s])
797797

798798
def test_reader_seconds(self, ext):
799-
import xlrd
800799

801800
# Test reading times with and without milliseconds. GH5945.
802-
if LooseVersion(xlrd.__VERSION__) >= LooseVersion("0.9.3"):
803-
# Xlrd >= 0.9.3 can handle Excel milliseconds.
804-
expected = DataFrame.from_dict({"Time": [time(1, 2, 3),
805-
time(2, 45, 56, 100000),
806-
time(4, 29, 49, 200000),
807-
time(6, 13, 42, 300000),
808-
time(7, 57, 35, 400000),
809-
time(9, 41, 28, 500000),
810-
time(11, 25, 21, 600000),
811-
time(13, 9, 14, 700000),
812-
time(14, 53, 7, 800000),
813-
time(16, 37, 0, 900000),
814-
time(18, 20, 54)]})
815-
else:
816-
# Xlrd < 0.9.3 rounds Excel milliseconds.
817-
expected = DataFrame.from_dict({"Time": [time(1, 2, 3),
818-
time(2, 45, 56),
819-
time(4, 29, 49),
820-
time(6, 13, 42),
821-
time(7, 57, 35),
822-
time(9, 41, 29),
823-
time(11, 25, 22),
824-
time(13, 9, 15),
825-
time(14, 53, 8),
826-
time(16, 37, 1),
827-
time(18, 20, 54)]})
801+
expected = DataFrame.from_dict({"Time": [time(1, 2, 3),
802+
time(2, 45, 56, 100000),
803+
time(4, 29, 49, 200000),
804+
time(6, 13, 42, 300000),
805+
time(7, 57, 35, 400000),
806+
time(9, 41, 28, 500000),
807+
time(11, 25, 21, 600000),
808+
time(13, 9, 14, 700000),
809+
time(14, 53, 7, 800000),
810+
time(16, 37, 0, 900000),
811+
time(18, 20, 54)]})
828812

829813
actual = self.get_exceldf('times_1900', ext, 'Sheet1')
830814
tm.assert_frame_equal(actual, expected)

0 commit comments

Comments
 (0)