Skip to content

Commit f3773a8

Browse files
Backport PR #39355: BUG: read_excel failing to check older xlrd versions properly (#39535)
Co-authored-by: Thomas Li <[email protected]>
1 parent d4c18af commit f3773a8

File tree

6 files changed

+10
-9
lines changed

6 files changed

+10
-9
lines changed

doc/source/whatsnew/v1.2.2.rst

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ including other versions of pandas.
1414

1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
17+
18+
- Fixed regression in :func:`read_excel` that caused it to raise ``AttributeError`` when checking version of older xlrd versions (:issue:`38955`)
1719
- Fixed regression in :class:`DataFrame` constructor reordering element when construction from datetime ndarray with dtype not ``"datetime64[ns]"`` (:issue:`39422`)
1820
- Fixed regression in :meth:`~DataFrame.to_pickle` failing to create bz2/xz compressed pickle files with ``protocol=5`` (:issue:`39002`)
1921
- Fixed regression in :func:`pandas.testing.assert_series_equal` and :func:`pandas.testing.assert_frame_equal` always raising ``AssertionError`` when comparing extension dtypes (:issue:`39410`)

pandas/compat/_optional.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
}
4747

4848

49-
def _get_version(module: types.ModuleType) -> str:
49+
def get_version(module: types.ModuleType) -> str:
5050
version = getattr(module, "__version__", None)
5151
if version is None:
5252
# xlrd uses a capitalized attribute name
@@ -112,7 +112,7 @@ def import_optional_dependency(
112112

113113
minimum_version = VERSIONS.get(name)
114114
if minimum_version:
115-
version = _get_version(module)
115+
version = get_version(module)
116116
if distutils.version.LooseVersion(version) < minimum_version:
117117
assert on_version in {"warn", "raise", "ignore"}
118118
msg = (

pandas/io/excel/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from pandas._libs.parsers import STR_NA_VALUES
1515
from pandas._typing import Buffer, FilePathOrBuffer, StorageOptions
16-
from pandas.compat._optional import import_optional_dependency
16+
from pandas.compat._optional import get_version, import_optional_dependency
1717
from pandas.errors import EmptyDataError
1818
from pandas.util._decorators import Appender, deprecate_nonkeyword_arguments, doc
1919

@@ -1049,7 +1049,7 @@ def __init__(
10491049
else:
10501050
import xlrd
10511051

1052-
xlrd_version = LooseVersion(xlrd.__version__)
1052+
xlrd_version = LooseVersion(get_version(xlrd))
10531053

10541054
if xlrd_version is not None and isinstance(path_or_buffer, xlrd.Book):
10551055
ext = "xls"

pandas/tests/io/excel/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from pandas.compat._optional import import_optional_dependency
5+
from pandas.compat._optional import get_version, import_optional_dependency
66

77
pytestmark = [
88
pytest.mark.filterwarnings(
@@ -32,4 +32,4 @@
3232
else:
3333
import xlrd
3434

35-
xlrd_version = LooseVersion(xlrd.__version__)
35+
xlrd_version = LooseVersion(get_version(xlrd))

pandas/util/_print_versions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Dict, Optional, Union
99

1010
from pandas._typing import JSONSerializable
11-
from pandas.compat._optional import VERSIONS, _get_version, import_optional_dependency
11+
from pandas.compat._optional import VERSIONS, get_version, import_optional_dependency
1212

1313

1414
def _get_commit_hash() -> Optional[str]:
@@ -83,7 +83,7 @@ def _get_dependency_info() -> Dict[str, JSONSerializable]:
8383
mod = import_optional_dependency(
8484
modname, raise_on_missing=False, on_version="ignore"
8585
)
86-
result[modname] = _get_version(mod) if mod else None
86+
result[modname] = get_version(mod) if mod else None
8787
return result
8888

8989

scripts/validate_unwanted_patterns.py

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"_doc_template",
3030
"_agg_template",
3131
"_pipe_template",
32-
"_get_version",
3332
"__main__",
3433
"_transform_template",
3534
"_flex_comp_doc_FRAME",

0 commit comments

Comments
 (0)