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

test: add symbols errors #293

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Binary file added python/tests/fixtures/symbols-errors.xlsx
Binary file not shown.
43 changes: 43 additions & 0 deletions python/tests/test_fastexcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,46 @@ def test_null_values_in_cells() -> None:
def test_null_column_is_nullable() -> None:
sheet = fastexcel.read_excel(path_for_fixture("null-column.xlsx")).load_sheet(0)
assert sheet.to_arrow().schema.field("nullonly").nullable is True


def test_symbols_errors() -> None:
reader = fastexcel.read_excel(path_for_fixture("symbols-errors.xlsx"))

# Reading the sheet with only the first row as the schema forces columns
# to be numbers and discards errors like #DIV/0! and #VALUE!
pl_assert_frame_equal(
reader.load_sheet(0, schema_sample_rows=1).to_polars(),
pl.DataFrame(
{
"a": [1.1, 2.2, None],
"b": [2.0, 0.0, 1.0],
"a/b": [0.55, None, None],
}
),
)

# Reading the sheet with all the rows as the schema forces columns
# to be strings and keeps the errors like #DIV/0! and #VALUE!
pl_assert_frame_equal(
reader.load_sheet(0, schema_sample_rows=3).to_polars(),
pl.DataFrame(
{
"a": ["1.1", "2.2", "abc"],
"b": [2.0, 0.0, 1.0],
"a/b": ["0.55", "#DIV/0!", "#VALUE!"],
}
),
)

# Reading the sheet with only the first row as the schema forces columns
# But casting it to strings will keep the errors like #DIV/0! and #VALUE!
pl_assert_frame_equal(
reader.load_sheet(0, schema_sample_rows=1, dtypes={"a/b": "string"}).to_polars(),
pl.DataFrame(
{
"a": [1.1, 2.2, None],
"b": [2.0, 0.0, 1.0],
"a/b": ["0.55", "#DIV/0!", "#VALUE!"],
}
),
)
Loading