From 6ad3ce82d01e10b8addb74a2b3ec879d5c8cd400 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Sat, 13 Feb 2021 08:53:11 -0500 Subject: [PATCH] CLN: Better method of determining read-only status of openpyxl worksheet --- pandas/io/excel/_openpyxl.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pandas/io/excel/_openpyxl.py b/pandas/io/excel/_openpyxl.py index 3a753a707166e..d0fe64a82d187 100644 --- a/pandas/io/excel/_openpyxl.py +++ b/pandas/io/excel/_openpyxl.py @@ -538,11 +538,7 @@ def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]: version = LooseVersion(get_version(openpyxl)) - # There is no good way of determining if a sheet is read-only - # https://foss.heptapod.net/openpyxl/openpyxl/-/issues/1605 - is_readonly = hasattr(sheet, "reset_dimensions") - - if version >= "3.0.0" and is_readonly: + if version >= "3.0.0" and self.book.read_only: sheet.reset_dimensions() data: List[List[Scalar]] = [] @@ -556,7 +552,7 @@ def get_sheet_data(self, sheet, convert_float: bool) -> List[List[Scalar]]: # Trim trailing empty rows data = data[: last_row_with_data + 1] - if version >= "3.0.0" and is_readonly and len(data) > 0: + if version >= "3.0.0" and self.book.read_only and len(data) > 0: # With dimension reset, openpyxl no longer pads rows max_width = max(len(data_row) for data_row in data) if min(len(data_row) for data_row in data) < max_width: