Skip to content
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

feat(python): Optimise read_excel when using "calamine" engine with the latest fastexcel #17735

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
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
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