delta-io / delta-rs

A native Rust library for Delta Lake, with bindings into Python
https://delta-io.github.io/delta-rs/
Apache License 2.0
2.35k stars 413 forks source link

[BUG]write_delta({'custom_metadata':str}) cannot be converted. str to pyDict error (0.18.2_DeltaPython/Windows10) #2697

Closed starzar closed 4 months ago

starzar commented 4 months ago

Bug

0.18.2_DeltaPython/Windows10

Describe the problem

write_deltalake_pyarrow(TypeError: argument 'custom_metadata': 'str' object cannot be converted to 'PyDict'

Steps to reproduce

import polars as pl
import datetime
datetime_cur = datetime.datetime.now()
datetime_cur_str = datetime_cur.strftime("%Y-%m-%d")
data = {
    "timestamp": [datetime_cur, datetime_cur + datetime.timedelta(days=1)],
    "alphabet": ["A", "B"]
}

_df = pl.DataFrame(data)

print(_df)
print('datetime_cur_str')
print(type(datetime_cur_str))
print(datetime_cur_str)
_deltapath = r'Others/Polars/tests'

# error occurs for both engines : 'engine': 'pyarrow'/'rust'
_df.write_delta(target=_deltapath, mode="overwrite", overwrite_schema=False,
                            delta_write_options={'engine': 'pyarrow', 'custom_metadata': datetime_cur_str})

-->

Observed results

Traceback (most recent call last):
  File "C:\Users\User_0\Documents\Code\Python\NseScraping\Others\Polars\tests\deltalake1.py", line 20, in <module>
    _df.write_delta(target=_deltapath, mode="overwrite", overwrite_schema=False,
  File "C:\Users\User_0\AppData\Local\Programs\Python\Python312\Lib\site-packages\polars\dataframe\frame.py", line 3877, in write_delta
    write_deltalake(
  File "C:\Users\User_0\AppData\Local\Programs\Python\Python312\Lib\site-packages\deltalake\writer.py", line 543, in write_deltalake
    write_deltalake_pyarrow(
TypeError: argument 'custom_metadata': 'str' object cannot be converted to 'PyDict'

Expected results

Further details

Environment information

Willingness to contribute

The Delta Lake Community encourages bug fix contributions. Would you or another member of your organization be willing to contribute a fix for this bug to the Delta Lake code base?

MrPowers commented 4 months ago

Thanks for opening this! Looks like this is for the delta-rs repo, going to transfer this issue now.

ion-elgreco commented 4 months ago

@starzar this isn't a bug. Custom metadata takes a dict[str,str] as value