diff --git a/doc/source/whatsnew/v1.2.2.rst b/doc/source/whatsnew/v1.2.2.rst index c5825d0881515..51535501f5c1b 100644 --- a/doc/source/whatsnew/v1.2.2.rst +++ b/doc/source/whatsnew/v1.2.2.rst @@ -14,6 +14,8 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ + +- Fixed regression in :func:`read_excel` that caused it to raise ``AttributeError`` when checking version of older xlrd versions (:issue:`38955`) - Fixed regression in :class:`DataFrame` constructor reordering element when construction from datetime ndarray with dtype not ``"datetime64[ns]"`` (:issue:`39422`) - Fixed regression in :meth:`~DataFrame.to_pickle` failing to create bz2/xz compressed pickle files with ``protocol=5`` (:issue:`39002`) - 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`) diff --git a/pandas/compat/_optional.py b/pandas/compat/_optional.py index 6110ca794e2c2..35c7b6547431f 100644 --- a/pandas/compat/_optional.py +++ b/pandas/compat/_optional.py @@ -48,7 +48,7 @@ } -def _get_version(module: types.ModuleType) -> str: +def get_version(module: types.ModuleType) -> str: version = getattr(module, "__version__", None) if version is None: # xlrd uses a capitalized attribute name @@ -126,7 +126,7 @@ def import_optional_dependency( module_to_get = module minimum_version = min_version if min_version is not None else VERSIONS.get(parent) if minimum_version: - version = _get_version(module_to_get) + version = get_version(module_to_get) if distutils.version.LooseVersion(version) < minimum_version: msg = ( f"Pandas requires version '{minimum_version}' or newer of '{parent}' " diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 11974d25d72d3..ab0cdd19b4acf 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -15,7 +15,7 @@ from pandas._libs.parsers import STR_NA_VALUES from pandas._typing import Buffer, DtypeArg, FilePathOrBuffer, StorageOptions -from pandas.compat._optional import import_optional_dependency +from pandas.compat._optional import get_version, import_optional_dependency from pandas.errors import EmptyDataError from pandas.util._decorators import Appender, deprecate_nonkeyword_arguments, doc @@ -1056,7 +1056,7 @@ def __init__( else: import xlrd - xlrd_version = LooseVersion(xlrd.__version__) + xlrd_version = LooseVersion(get_version(xlrd)) if xlrd_version is not None and isinstance(path_or_buffer, xlrd.Book): ext = "xls" diff --git a/pandas/tests/io/excel/__init__.py b/pandas/tests/io/excel/__init__.py index 7df035e6da17a..b1038f0314f41 100644 --- a/pandas/tests/io/excel/__init__.py +++ b/pandas/tests/io/excel/__init__.py @@ -2,7 +2,7 @@ import pytest -from pandas.compat._optional import import_optional_dependency +from pandas.compat._optional import get_version, import_optional_dependency pytestmark = [ pytest.mark.filterwarnings( @@ -29,4 +29,4 @@ else: import xlrd - xlrd_version = LooseVersion(xlrd.__version__) + xlrd_version = LooseVersion(get_version(xlrd)) diff --git a/pandas/util/_print_versions.py b/pandas/util/_print_versions.py index 381dab4e3ce45..ae3c8c98f8dc1 100644 --- a/pandas/util/_print_versions.py +++ b/pandas/util/_print_versions.py @@ -8,7 +8,7 @@ from typing import Dict, Optional, Union from pandas._typing import JSONSerializable -from pandas.compat._optional import VERSIONS, _get_version, import_optional_dependency +from pandas.compat._optional import VERSIONS, get_version, import_optional_dependency def _get_commit_hash() -> Optional[str]: @@ -81,7 +81,7 @@ def _get_dependency_info() -> Dict[str, JSONSerializable]: result: Dict[str, JSONSerializable] = {} for modname in deps: mod = import_optional_dependency(modname, errors="ignore") - result[modname] = _get_version(mod) if mod else None + result[modname] = get_version(mod) if mod else None return result diff --git a/scripts/validate_unwanted_patterns.py b/scripts/validate_unwanted_patterns.py index 9c58a55cb907e..8f48d518a737b 100755 --- a/scripts/validate_unwanted_patterns.py +++ b/scripts/validate_unwanted_patterns.py @@ -29,7 +29,6 @@ "_doc_template", "_agg_template", "_pipe_template", - "_get_version", "__main__", "_transform_template", "_flex_comp_doc_FRAME",