Skip to content

Commit

Permalink
Remove read_excel hacks (#4081)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Jul 22, 2022
1 parent ecc197f commit 2dece04
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
20 changes: 3 additions & 17 deletions py-polars/polars/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,26 +1075,12 @@ def read_excel(
if not read_csv_options:
read_csv_options = {}

# Override xlsx2csv eprint function so in case an error occurs
# it raises an exception instead of writing to stderr.
def _eprint(*args: Any, **kwargs: Any) -> None:
raise xlsx2csv.XlsxException(format(*args))

xlsx2csv.eprint = _eprint

# Create Xlsx2csv instance.
xlsx2csv_instance = xlsx2csv.Xlsx2csv(file, **xlsx2csv_options)

if sheet_name:
sheet_id = xlsx2csv_instance.getSheetIdByName(sheet_name)

if not sheet_id:
raise xlsx2csv.XlsxException(f"Sheet '{sheet_name}' not found.")

csv_buffer = StringIO()

# Convert sheet from XSLX document to CSV.
xlsx2csv_instance.convert(outfile=csv_buffer, sheetid=sheet_id)
xlsx2csv.Xlsx2csv(file, **xlsx2csv_options).convert(
outfile=csv_buffer, sheetid=sheet_id, sheetname=sheet_name
)

# Rewind buffer to start.
csv_buffer.seek(0)
Expand Down
2 changes: 1 addition & 1 deletion py-polars/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pandas = ["pyarrow>=4.0.*", "pandas"]
numpy = ["numpy >= 1.16.0"]
fsspec = ["fsspec"]
connectorx = ["connectorx"]
xlsx2csv = ["xlsx2csv"]
xlsx2csv = ["xlsx2csv >= 0.8.0"]

[tool.isort]
profile = "black"
Expand Down

0 comments on commit 2dece04

Please sign in to comment.