Skip to content

Commit ddbf377

Browse files
authored
BUG: read_excel failing to check older xlrd versions properly (#39355)
1 parent b683e51 commit ddbf377

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
@@ -48,7 +48,7 @@
4848
}
4949

5050

51-
def _get_version(module: types.ModuleType) -> str:
51+
def get_version(module: types.ModuleType) -> str:
5252
version = getattr(module, "__version__", None)
5353
if version is None:
5454
# xlrd uses a capitalized attribute name
@@ -126,7 +126,7 @@ def import_optional_dependency(
126126
module_to_get = module
127127
minimum_version = min_version if min_version is not None else VERSIONS.get(parent)
128128
if minimum_version:
129-
version = _get_version(module_to_get)
129+
version = get_version(module_to_get)
130130
if distutils.version.LooseVersion(version) < minimum_version:
131131
msg = (
132132
f"Pandas requires version '{minimum_version}' or newer of '{parent}' "

pandas/io/excel/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from pandas._libs.parsers import STR_NA_VALUES
1717
from pandas._typing import Buffer, DtypeArg, FilePathOrBuffer, StorageOptions
18-
from pandas.compat._optional import import_optional_dependency
18+
from pandas.compat._optional import get_version, import_optional_dependency
1919
from pandas.errors import EmptyDataError
2020
from pandas.util._decorators import Appender, deprecate_nonkeyword_arguments, doc
2121

@@ -1056,7 +1056,7 @@ def __init__(
10561056
else:
10571057
import xlrd
10581058

1059-
xlrd_version = LooseVersion(xlrd.__version__)
1059+
xlrd_version = LooseVersion(get_version(xlrd))
10601060

10611061
if xlrd_version is not None and isinstance(path_or_buffer, xlrd.Book):
10621062
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(
@@ -29,4 +29,4 @@
2929
else:
3030
import xlrd
3131

32-
xlrd_version = LooseVersion(xlrd.__version__)
32+
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]:
@@ -81,7 +81,7 @@ def _get_dependency_info() -> Dict[str, JSONSerializable]:
8181
result: Dict[str, JSONSerializable] = {}
8282
for modname in deps:
8383
mod = import_optional_dependency(modname, errors="ignore")
84-
result[modname] = _get_version(mod) if mod else None
84+
result[modname] = get_version(mod) if mod else None
8585
return result
8686

8787

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)