Skip to content

Commit d84cc02

Browse files
committed
Merge remote-tracking branch 'upstream/master' into ea-repr
2 parents 2b5fe25 + deb7b4d commit d84cc02

File tree

11 files changed

+47
-76
lines changed

11 files changed

+47
-76
lines changed

ci/deps/azure-27-compat.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies:
1616
- pytz=2013b
1717
- scipy=0.18.1
1818
- sqlalchemy=0.7.8
19-
- xlrd=0.9.2
19+
- xlrd=1.0.0
2020
- xlsxwriter=0.5.2
2121
- xlwt=0.7.5
2222
# universal

ci/deps/travis-27-locale.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies:
1616
- pytz=2013b
1717
- scipy
1818
- sqlalchemy=0.8.1
19-
- xlrd=0.9.2
19+
- xlrd=1.0.0
2020
- xlsxwriter=0.5.2
2121
- xlwt=0.7.5
2222
# universal

ci/deps/travis-27.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies:
3535
- scipy
3636
- sqlalchemy=0.9.6
3737
- xarray=0.9.6
38-
- xlrd=0.9.2
38+
- xlrd=1.0.0
3939
- xlsxwriter=0.5.2
4040
- xlwt=0.7.5
4141
# universal

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

doc/source/whatsnew/v0.24.0.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ Backwards incompatible API changes
307307
Dependencies have increased minimum versions
308308
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
309309

310-
We have updated our minimum supported versions of dependencies (:issue:`21242`, `18742`).
310+
We have updated our minimum supported versions of dependencies (:issue:`21242`, :issue:`18742`, :issue:`23774`).
311311
If installed, we now require:
312312

313313
+-----------------+-----------------+----------+
@@ -331,6 +331,8 @@ If installed, we now require:
331331
+-----------------+-----------------+----------+
332332
| scipy | 0.18.1 | |
333333
+-----------------+-----------------+----------+
334+
| xlrd | 1.0.0 | |
335+
+-----------------+-----------------+----------+
334336

335337
Additionally we no longer depend on `feather-format` for feather based storage
336338
and replaced it with references to `pyarrow` (:issue:`21639` and :issue:`23053`).

pandas/_libs/algos_rank_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def rank_1d_{{dtype}}(object in_arr, ties_method='average',
126126

127127
sorted_data = values.take(_as)
128128
sorted_mask = mask.take(_as)
129-
_indices = np.diff(sorted_mask).nonzero()[0]
129+
_indices = np.diff(sorted_mask.astype(int)).nonzero()[0]
130130
non_na_idx = _indices[0] if len(_indices) > 0 else -1
131131
argsorted = _as.astype('i8')
132132

pandas/_libs/index.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ cdef class IndexEngine:
113113
if not self.is_unique:
114114
return self._get_loc_duplicates(val)
115115
values = self._get_index_values()
116+
117+
self._check_type(val)
116118
loc = _bin_search(values, val) # .searchsorted(val, side='left')
117119
if loc >= len(values):
118120
raise KeyError(val)

pandas/_libs/index_class_helper.pxi.in

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ cdef class {{name}}Engine(IndexEngine):
5151
raise KeyError(val)
5252
elif util.is_float_object(val):
5353
raise KeyError(val)
54+
elif not util.is_integer_object(val):
55+
raise KeyError(val)
5456
{{endif}}
5557

5658
{{if name != 'Object'}}

pandas/core/indexes/period.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from pandas.core.arrays.period import PeriodArray, period_array
3434
from pandas.core.base import _shared_docs
3535
from pandas.core.indexes.base import _index_shared_docs, ensure_index
36+
from pandas.core.missing import isna
3637

3738
from pandas import compat
3839
from pandas.util._decorators import (
@@ -652,7 +653,8 @@ def get_value(self, series, key):
652653
except TypeError:
653654
pass
654655

655-
key = Period(key, self.freq).ordinal
656+
period = Period(key, self.freq)
657+
key = period.value if isna(period) else period.ordinal
656658
return com.maybe_box(self, self._engine.get_value(s, key),
657659
series, key)
658660

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)