Skip to content

BUG: read_excel failing to check older xlrd versions properly #39355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 1, 2021
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v1.2.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
4 changes: 2 additions & 2 deletions pandas/compat/_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}' "
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/excel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -29,4 +29,4 @@
else:
import xlrd

xlrd_version = LooseVersion(xlrd.__version__)
xlrd_version = LooseVersion(get_version(xlrd))
4 changes: 2 additions & 2 deletions pandas/util/_print_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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


Expand Down
1 change: 0 additions & 1 deletion scripts/validate_unwanted_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"_doc_template",
"_agg_template",
"_pipe_template",
"_get_version",
"__main__",
"_transform_template",
"_flex_comp_doc_FRAME",
Expand Down