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(python): fixed large_dtype to schema convert #2635

Merged
merged 2 commits into from
Jun 29, 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
2 changes: 1 addition & 1 deletion python/deltalake/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def write_deltalake(
partition_by = [partition_by]

if isinstance(schema, DeltaSchema):
schema = schema.to_pyarrow(as_large_types=True)
schema = schema.to_pyarrow(as_large_types=large_dtypes)

if isinstance(data, RecordBatchReader):
data = convert_pyarrow_recordbatchreader(data, large_dtypes)
Expand Down
24 changes: 24 additions & 0 deletions python/tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,30 @@ def test_with_deltalake_schema(tmp_path: pathlib.Path, sample_data: pa.Table):
assert delta_table.schema().to_pyarrow() == sample_data.schema


def test_with_deltalake_json_schema(tmp_path: pathlib.Path):
json_schema = '{"type": "struct","fields": [{"name": "campaign", "type": "string", "nullable": true, "metadata": {}},{"name": "account", "type": "string", "nullable": true, "metadata": {}}]}'
table_schema = Schema.from_json(json_schema)
table = pa.table(
{
"campaign": pa.array([]),
"account": pa.array([]),
}
)
write_deltalake(tmp_path, table, schema=table_schema)
table = pa.table(
{
"campaign": pa.array(["deltaLake"]),
"account": pa.array(["admin"]),
}
)

write_deltalake(tmp_path, data=table, schema=table_schema, mode="append")

delta_table = DeltaTable(tmp_path)
assert delta_table.schema() == table_schema
assert delta_table.to_pyarrow_table() == table


def test_write_stats_empty_rowgroups(tmp_path: pathlib.Path):
# https://github.com/delta-io/delta-rs/issues/2169
data = pa.table(
Expand Down
Loading