Skip to content

Commit

Permalink
fix: take use_columns into account when loading a sheet eagerly (#260)
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Peschke <[email protected]>
  • Loading branch information
lukapeschke authored Jul 19, 2024
1 parent 441a973 commit 226cc48
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions python/tests/test_column_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,17 @@ def test_use_columns_with_bad_callable() -> None:
2,
use_columns=lambda _: 42, # type: ignore
)


def test_use_columns_with_eager_loading() -> None:
excel_reader = fastexcel.read_excel(path_for_fixture("fixture-single-sheet.xlsx"))

# default
rb = excel_reader.load_sheet_eager(0)
assert rb.schema.names == ["Month", "Year"]
# changing order
rb = excel_reader.load_sheet_eager(0, use_columns=["Year", "Month"])
assert rb.schema.names == ["Year", "Month"]
# subset
rb = excel_reader.load_sheet_eager(0, use_columns=["Year"])
assert rb.schema.names == ["Year"]
4 changes: 3 additions & 1 deletion src/types/python/excelreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ impl ExcelReader {
dtype_coercion,
)?;

let fields = available_columns
let final_columns = selected_columns.select_columns(&available_columns)?;

let fields = final_columns
.iter()
.map(Into::<Field>::into)
.collect::<Vec<_>>();
Expand Down

0 comments on commit 226cc48

Please sign in to comment.