Skip to content

[Bug]: write_deltalake doesn't raise ValueError if the schema of the data passed differs from the existing table's schema #3917

@nicolo-barboni

Description

@nicolo-barboni

What happened?

As the title suggests, an error doesn't get raised when the schemas are not matching.
Am i missing something?

Expected behavior

I would expect a ValueError, as described in the docs.

Image

Operating System

macOS

Binding

Python

Bindings Version

1.2.1

Steps to reproduce

import datetime

import deltalake
import polars as pl

schema1 = pl.Schema({'id': pl.Int64, 'name': pl.String, 'age': pl.Int64})
schema2 = pl.Schema({'id': pl.Int64, 'name': pl.String, 'age': pl.Date})
schema3 = pl.Schema({'id': pl.Int64, 'name': pl.String, 'age': pl.String})

df1 = pl.DataFrame({'id': [1, 2], 'name': ['Alice', 'Bob'], 'age': [25, 30]}, schema=schema1)
df2 = pl.DataFrame(
    {'id': [10, 11], 'name': ['Simon', 'Tom'], 'age': [datetime.date(2025, 1, 1), datetime.date(2025, 1, 2)]},
    schema=schema2,
)
df3 = pl.DataFrame(
    {'id': [10, 11], 'name': ['Kate', 'John'], 'age': ['25', '30']},
    schema=schema3,
)
delta_path = 'test_delta_table'

deltalake.write_deltalake(str(delta_path), df1, mode='append')
deltalake.write_deltalake(str(delta_path), df2, mode='append')
deltalake.write_deltalake(str(delta_path), df3, mode='append')

df_read = pl.read_delta(str(delta_path))
print(df_read)

### Relevant logs

```shell
shape: (6, 3)
┌─────┬───────┬───────┐
│ idnameage   │
│ ---------   │
│ i64stri64   │
╞═════╪═══════╪═══════╡
│ 10Kate25    │
│ 11John30    │
│ 10Simon20089 │
│ 11Tom20090 │
│ 1Alice25    │
│ 2Bob30    │
└─────┴───────┴───────┘

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions