Skip to content

Commit

Permalink
feat(python): Optimise read_excel when using "calamine" engine with…
Browse files Browse the repository at this point in the history
… the latest `fastexcel` (#17735)

Signed-off-by: Luka Peschke <[email protected]>
  • Loading branch information
lukapeschke authored Jul 24, 2024
1 parent 3981d47 commit 4c19115
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions py-polars/polars/io/spreadsheet/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import IO, TYPE_CHECKING, Any, Callable, NoReturn, Sequence, overload

import polars._reexport as pl
from polars import from_arrow
from polars import functions as F
from polars._utils.deprecation import (
deprecate_renamed_parameter,
Expand Down Expand Up @@ -882,8 +883,12 @@ def _read_spreadsheet_calamine(

read_options["dtypes"] = parser_dtypes

ws = parser.load_sheet_by_name(name=sheet_name, **read_options)
df = ws.to_polars()
if fastexcel_version < (0, 11, 2):
ws = parser.load_sheet_by_name(name=sheet_name, **read_options)
df = ws.to_polars()
else:
ws_arrow = parser.load_sheet_eager(sheet_name, **read_options)
df = from_arrow(ws_arrow)

# note: even if we applied parser dtypes we still re-apply schema_overrides
# natively as we can refine integer/float types, temporal precision, etc.
Expand Down
2 changes: 1 addition & 1 deletion py-polars/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cloudpickle
fsspec
s3fs[boto3]
# Spreadsheet
fastexcel>=0.9
fastexcel>=0.11.5
openpyxl
xlsx2csv
xlsxwriter
Expand Down

0 comments on commit 4c19115

Please sign in to comment.