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

fix: replace assert and AssertionError with appropriate exceptions #2286

Merged
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
12 changes: 7 additions & 5 deletions python/deltalake/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,18 @@ def sort_arrow_schema(schema: pa.schema) -> pa.schema:
f"Data schema:\n{schema}\nTable Schema:\n{table.schema().to_pyarrow(as_large_types=large_dtypes)}"
)
if mode == "error":
raise AssertionError("DeltaTable already exists.")
raise FileExistsError(
"Delta table already exists, write mode set to error."
)
elif mode == "ignore":
return

current_version = table.version()

if partition_by:
assert (
partition_by == table.metadata().partition_columns
), f"Partition columns should be {table.metadata().partition_columns} but is {partition_by}"
if partition_by and partition_by != table.metadata().partition_columns:
raise ValueError(
f"Partition columns should be {table.metadata().partition_columns} but is {partition_by}"
)
else:
partition_by = table.metadata().partition_columns

Expand Down
4 changes: 2 additions & 2 deletions python/tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def test_write_modes(tmp_path: pathlib.Path, sample_data: pa.Table, engine):
assert DeltaTable(tmp_path).to_pyarrow_table() == sample_data

if engine == "pyarrow":
with pytest.raises(AssertionError):
with pytest.raises(FileExistsError):
write_deltalake(tmp_path, sample_data, mode="error")
elif engine == "rust":
with pytest.raises(DeltaError):
Expand Down Expand Up @@ -481,7 +481,7 @@ def test_fails_wrong_partitioning(
existing_table: DeltaTable, sample_data: pa.Table, engine
):
if engine == "pyarrow":
with pytest.raises(AssertionError):
with pytest.raises(ValueError):
write_deltalake(
existing_table,
sample_data,
Expand Down
Loading