Skip to content

Change Scope of xlrd Import Attempt #26782

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions pandas/io/excel/_xlrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,26 @@
from pandas.io.excel._base import _BaseExcelReader


class _XlrdReader(_BaseExcelReader):

def __init__(self, filepath_or_buffer):
"""Reader using xlrd engine.

Parameters
----------
filepath_or_buffer : string, path object or Workbook
Object to be parsed.
"""
err_msg = "Install xlrd >= 1.0.0 for Excel support"
try:
import xlrd
from xlrd import (
Book, open_workbook, xldate, XL_CELL_DATE, XL_CELL_ERROR,
XL_CELL_BOOLEAN, XL_CELL_NUMBER)
except ImportError:
raise ImportError("Install xlrd >= 1.0.0 for Excel support")
else:
if xlrd.__VERSION__ < LooseVersion("1.0.0"):
raise ImportError("Install xlrd >= 1.0.0 for Excel support" +
". Current version " + xlrd.__VERSION__)

try:
import xlrd
except ImportError:
raise ImportError(err_msg)
else:
if xlrd.__VERSION__ < LooseVersion("1.0.0"):
raise ImportError(err_msg +
". Current version " + xlrd.__VERSION__)

super().__init__(filepath_or_buffer)
class _XlrdReader(_BaseExcelReader):

@property
def _workbook_class(self):
from xlrd import Book
return Book

def load_workbook(self, filepath_or_buffer):
from xlrd import open_workbook
if hasattr(filepath_or_buffer, "read"):
data = filepath_or_buffer.read()
return open_workbook(file_contents=data)
Expand All @@ -53,10 +43,6 @@ def get_sheet_by_index(self, index):
return self.book.sheet_by_index(index)

def get_sheet_data(self, sheet, convert_float):
from xlrd import (xldate, XL_CELL_DATE,
XL_CELL_ERROR, XL_CELL_BOOLEAN,
XL_CELL_NUMBER)

epoch1904 = self.book.datemode

def _parse_cell(cell_contents, cell_typ):
Expand Down