From 37e96c75b967d825c99f3d5618e856d551fb5c5b Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Sat, 23 Jan 2021 12:30:37 -0800 Subject: [PATCH 01/10] Update _base.py --- pandas/io/excel/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 11974d25d72d3..82f7c0019f634 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1056,7 +1056,7 @@ def __init__( else: import xlrd - xlrd_version = LooseVersion(xlrd.__version__) + xlrd_version = LooseVersion(xlrd.__VERSION__) if xlrd_version is not None and isinstance(path_or_buffer, xlrd.Book): ext = "xls" From cf3b8cefb293fce5f8db9ca511f5d104fa08e67e Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Sat, 23 Jan 2021 12:36:13 -0800 Subject: [PATCH 02/10] Update v1.2.2.rst --- doc/source/whatsnew/v1.2.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.2.rst b/doc/source/whatsnew/v1.2.2.rst index 5e96587a326d9..a5adf6b14b949 100644 --- a/doc/source/whatsnew/v1.2.2.rst +++ b/doc/source/whatsnew/v1.2.2.rst @@ -24,7 +24,7 @@ Fixed regressions Bug fixes ~~~~~~~~~ -- +- Fixed bug in ``read_excel()`` that caused it to fail when checking version of older xlrd versions(:issue:`38955`) - .. --------------------------------------------------------------------------- From 570e60d649bad88fa78444a130f4393586e4022c Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Sat, 23 Jan 2021 12:42:22 -0800 Subject: [PATCH 03/10] Update v1.2.2.rst --- doc/source/whatsnew/v1.2.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.2.rst b/doc/source/whatsnew/v1.2.2.rst index a5adf6b14b949..f7f60be3f3a73 100644 --- a/doc/source/whatsnew/v1.2.2.rst +++ b/doc/source/whatsnew/v1.2.2.rst @@ -24,7 +24,7 @@ Fixed regressions Bug fixes ~~~~~~~~~ -- Fixed bug in ``read_excel()`` that caused it to fail when checking version of older xlrd versions(:issue:`38955`) +- Fixed bug in :meth:``read_excel`` that caused it to fail when checking version of older xlrd versions(:issue:`38955`) - .. --------------------------------------------------------------------------- From 7bd431d2b01e7a83fcbef10c2af084d922ee98e2 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Mon, 25 Jan 2021 13:41:59 -0800 Subject: [PATCH 04/10] Update _base.py --- pandas/io/excel/_base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 82f7c0019f634..27a4a39171d63 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 @@ -1054,9 +1054,10 @@ def __init__( if import_optional_dependency("xlrd", errors="ignore") is None: xlrd_version = None else: + import xlrd - xlrd_version = LooseVersion(xlrd.__VERSION__) + xlrd_version = _get_version(xlrd) if xlrd_version is not None and isinstance(path_or_buffer, xlrd.Book): ext = "xls" From 060bf8db0462bb8108295cd84855c8fd21bed747 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Mon, 25 Jan 2021 13:43:52 -0800 Subject: [PATCH 05/10] Update __init__.py --- pandas/tests/io/excel/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/excel/__init__.py b/pandas/tests/io/excel/__init__.py index 7df035e6da17a..44c7c65699903 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 = _get_version(xlrd) From 3aa82055d6ed23e6bbe2ce76035b7e16b5871bed Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Mon, 25 Jan 2021 13:59:28 -0800 Subject: [PATCH 06/10] Fix formatting --- pandas/io/excel/_base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 27a4a39171d63..e3e2c6302e6bc 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1054,7 +1054,6 @@ def __init__( if import_optional_dependency("xlrd", errors="ignore") is None: xlrd_version = None else: - import xlrd xlrd_version = _get_version(xlrd) From f2d52c6839936d4b871dc36c418feac330f86a91 Mon Sep 17 00:00:00 2001 From: Thomas Li Date: Thu, 28 Jan 2021 11:29:24 -0800 Subject: [PATCH 07/10] Address code review --- doc/source/whatsnew/v1.2.2.rst | 4 ++-- pandas/io/excel/_base.py | 2 +- pandas/tests/io/excel/__init__.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v1.2.2.rst b/doc/source/whatsnew/v1.2.2.rst index f7f60be3f3a73..b5c78db0c441f 100644 --- a/doc/source/whatsnew/v1.2.2.rst +++ b/doc/source/whatsnew/v1.2.2.rst @@ -14,7 +14,7 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ -- +- Fixed bug in :meth:``read_excel`` that caused it to fail when checking version of older xlrd versions(:issue:`38955`) - .. --------------------------------------------------------------------------- @@ -24,7 +24,7 @@ Fixed regressions Bug fixes ~~~~~~~~~ -- Fixed bug in :meth:``read_excel`` that caused it to fail when checking version of older xlrd versions(:issue:`38955`) +- - .. --------------------------------------------------------------------------- diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index e3e2c6302e6bc..cf85f77683aee 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1056,7 +1056,7 @@ def __init__( else: import xlrd - xlrd_version = _get_version(xlrd) + 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 44c7c65699903..22e73ef575725 100644 --- a/pandas/tests/io/excel/__init__.py +++ b/pandas/tests/io/excel/__init__.py @@ -29,4 +29,4 @@ else: import xlrd - xlrd_version = _get_version(xlrd) + xlrd_version = LooseVersion(_get_version(xlrd)) From 95cdcd4e907bfa3c16f72aae6a6c7155f254705b Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Sat, 30 Jan 2021 13:12:25 -0800 Subject: [PATCH 08/10] Update doc/source/whatsnew/v1.2.2.rst Co-authored-by: Simon Hawkins --- doc/source/whatsnew/v1.2.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.2.rst b/doc/source/whatsnew/v1.2.2.rst index 89f7df318db0c..3c4098f9b7862 100644 --- a/doc/source/whatsnew/v1.2.2.rst +++ b/doc/source/whatsnew/v1.2.2.rst @@ -14,7 +14,7 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ -- Fixed bug in :meth:``read_excel`` that caused it to fail when checking version of older xlrd versions(:issue:`38955`) +- Fixed regression in :func:`read_excel` that caused it to raise ``AttributeError`` when checking version of older xlrd versions (:issue:`38955`) - 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`) - From 5dd7f6fa50997adf47a1a4442caade0f547d48fc Mon Sep 17 00:00:00 2001 From: Thomas Li Date: Sat, 30 Jan 2021 13:15:06 -0800 Subject: [PATCH 09/10] Make get_version public --- pandas/compat/_optional.py | 4 ++-- pandas/io/excel/_base.py | 4 ++-- pandas/tests/io/excel/__init__.py | 4 ++-- pandas/util/_print_versions.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) 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 cf85f77683aee..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 _get_version, 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(_get_version(xlrd)) + 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 22e73ef575725..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 _get_version, 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(_get_version(xlrd)) + 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 From 47d6a1d5129fbeb589975b427bec0036c1b722e4 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Sat, 30 Jan 2021 18:24:58 -0800 Subject: [PATCH 10/10] Update validate_unwanted_patterns.py --- scripts/validate_unwanted_patterns.py | 1 - 1 file changed, 1 deletion(-) 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",