Skip to content

Commit d5d43e0

Browse files
authored
DEP: bump min version of openpyxl to 3.0.0 #39603 (#39702)
1 parent a9cacd9 commit d5d43e0

File tree

7 files changed

+8
-26
lines changed

7 files changed

+8
-26
lines changed

ci/deps/azure-37-locale_slow.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818
- lxml
1919
- matplotlib=3.0.0
2020
- numpy=1.16.*
21-
- openpyxl=2.6.0
21+
- openpyxl=3.0.0
2222
- python-dateutil
2323
- python-blosc
2424
- pytz=2017.3

ci/deps/azure-37-minimum_versions.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies:
1919
- numba=0.46.0
2020
- numexpr=2.6.8
2121
- numpy=1.16.5
22-
- openpyxl=2.6.0
22+
- openpyxl=3.0.0
2323
- pytables=3.5.1
2424
- python-dateutil=2.7.3
2525
- pytz=2017.3

doc/source/getting_started/install.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ html5lib 1.0.1 HTML parser for read_html (see :ref
274274
lxml 4.3.0 HTML parser for read_html (see :ref:`note <optional_html>`)
275275
matplotlib 2.2.3 Visualization
276276
numba 0.46.0 Alternative execution engine for rolling operations
277-
openpyxl 2.6.0 Reading / writing for xlsx files
277+
openpyxl 3.0.0 Reading / writing for xlsx files
278278
pandas-gbq 0.12.0 Google Big Query access
279279
psycopg2 2.7 PostgreSQL engine for sqlalchemy
280280
pyarrow 0.15.0 Parquet, ORC, and feather reading / writing

doc/source/whatsnew/v1.3.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Optional libraries below the lowest tested version may still work, but are not c
186186
+-----------------+-----------------+---------+
187187
| numba | 0.46.0 | |
188188
+-----------------+-----------------+---------+
189-
| openpyxl | 2.6.0 | |
189+
| openpyxl | 3.0.0 | X |
190190
+-----------------+-----------------+---------+
191191
| pyarrow | 0.15.0 | |
192192
+-----------------+-----------------+---------+

pandas/compat/_optional.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"matplotlib": "2.2.3",
1818
"numexpr": "2.6.8",
1919
"odfpy": "1.3.0",
20-
"openpyxl": "2.6.0",
20+
"openpyxl": "3.0.0",
2121
"pandas_gbq": "0.12.0",
2222
"pyarrow": "0.15.0",
2323
"pytest": "5.0.1",

pandas/io/excel/_openpyxl.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from __future__ import annotations
22

3-
from distutils.version import LooseVersion
43
import mmap
54
from typing import TYPE_CHECKING, Dict, List, Optional
65

76
import numpy as np
87

98
from pandas._typing import FilePathOrBuffer, Scalar, StorageOptions
10-
from pandas.compat._optional import get_version, import_optional_dependency
9+
from pandas.compat._optional import import_optional_dependency
1110

1211
from pandas.io.excel._base import BaseExcelReader, ExcelWriter
1312
from pandas.io.excel._util import validate_freeze_panes
@@ -531,14 +530,8 @@ def _convert_cell(self, cell, convert_float: bool) -> Scalar:
531530
return cell.value
532531

533532
def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]:
534-
# GH 39001
535-
# Reading of excel file depends on dimension data being correct but
536-
# writers sometimes omit or get it wrong
537-
import openpyxl
538533

539-
version = LooseVersion(get_version(openpyxl))
540-
541-
if version >= "3.0.0" and self.book.read_only:
534+
if self.book.read_only:
542535
sheet.reset_dimensions()
543536

544537
data: List[List[Scalar]] = []
@@ -552,7 +545,7 @@ def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]:
552545
# Trim trailing empty rows
553546
data = data[: last_row_with_data + 1]
554547

555-
if version >= "3.0.0" and self.book.read_only and len(data) > 0:
548+
if self.book.read_only and len(data) > 0:
556549
# With dimension reset, openpyxl no longer pads rows
557550
max_width = max(len(data_row) for data_row in data)
558551
if min(len(data_row) for data_row in data) < max_width:

pandas/tests/io/excel/test_openpyxl.py

-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
from distutils.version import LooseVersion
21
from pathlib import Path
32

43
import numpy as np
54
import pytest
65

7-
from pandas.compat._optional import get_version
8-
96
import pandas as pd
107
from pandas import DataFrame
118
import pandas._testing as tm
@@ -157,10 +154,6 @@ def test_read_with_bad_dimension(
157154
datapath, ext, header, expected_data, filename, read_only, request
158155
):
159156
# GH 38956, 39001 - no/incorrect dimension information
160-
version = LooseVersion(get_version(openpyxl))
161-
if (read_only or read_only is None) and version < "3.0.0":
162-
msg = "openpyxl read-only sheet is incorrect when dimension data is wrong"
163-
request.node.add_marker(pytest.mark.xfail(reason=msg))
164157
path = datapath("io", "data", "excel", f"{filename}{ext}")
165158
if read_only is None:
166159
result = pd.read_excel(path, header=header)
@@ -195,10 +188,6 @@ def test_append_mode_file(ext):
195188
@pytest.mark.parametrize("read_only", [True, False, None])
196189
def test_read_with_empty_trailing_rows(datapath, ext, read_only, request):
197190
# GH 39181
198-
version = LooseVersion(get_version(openpyxl))
199-
if (read_only or read_only is None) and version < "3.0.0":
200-
msg = "openpyxl read-only sheet is incorrect when dimension data is wrong"
201-
request.node.add_marker(pytest.mark.xfail(reason=msg))
202191
path = datapath("io", "data", "excel", f"empty_trailing_rows{ext}")
203192
if read_only is None:
204193
result = pd.read_excel(path)

0 commit comments

Comments
 (0)