Skip to content

Commit

Permalink
test: move and fix name of test
Browse files Browse the repository at this point in the history
  • Loading branch information
PrettyWood committed Jun 30, 2024
1 parent 4332278 commit 162cde3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 74 deletions.
66 changes: 66 additions & 0 deletions python/tests/test_column_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,69 @@ def test_single_sheet_invalid_column_indices_column_does_not_exist_int(
"""
with pytest.raises(fastexcel.ColumnNotFoundError, match=expected_message):
excel_reader_single_sheet_with_unnamed_columns.load_sheet(0, use_columns=[42])


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

sheet = excel_reader.load_sheet(
0,
use_columns=[1, 2],
header_row=None,
skip_rows=1,
column_names=["bools_renamed", "dates_renamed"],
)

assert sheet.available_columns == [
fastexcel.ColumnInfo(
name="__UNNAMED__0",
column_name_from="generated",
index=0,
dtype="float",
dtype_from="guessed",
),
fastexcel.ColumnInfo(
name="bools_renamed",
index=1,
dtype="boolean",
dtype_from="guessed",
column_name_from="provided",
),
fastexcel.ColumnInfo(
name="dates_renamed",
index=2,
dtype="datetime",
dtype_from="guessed",
column_name_from="provided",
),
fastexcel.ColumnInfo(
name="__UNNAMED__3",
index=3,
dtype="float",
dtype_from="guessed",
column_name_from="generated",
),
]

pd_assert_frame_equal(
sheet.to_pandas(),
pd.DataFrame(
{
"bools_renamed": [True, False, True],
"dates_renamed": pd.Series([pd.Timestamp("2022-03-02 05:43:04")] * 3).astype(
"datetime64[ms]"
),
}
),
)
pl_assert_frame_equal(
sheet.to_polars(),
pl.DataFrame(
{
"bools_renamed": [True, False, True],
"dates_renamed": ["2022-03-02 05:43:04"] * 3,
}
).with_columns(
pl.col("dates_renamed").str.strptime(pl.Datetime, "%F %T").dt.cast_time_unit("ms")
),
)
74 changes: 0 additions & 74 deletions python/tests/test_use_columns.py

This file was deleted.

0 comments on commit 162cde3

Please sign in to comment.