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

Cannot read the delta table if that table was written with a dataframe that had columns with categorical dtype. #20438

Open
2 tasks done
SidPharVision opened this issue Dec 24, 2024 · 0 comments
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@SidPharVision
Copy link

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

import polars as pl

# Create a hard-coded DataFrame with a string column
df = pl.DataFrame({
    "id": [1, 2, 3, 4, 5],
    "value": [0.5, 0.8, 0.3, 0.9, 0.1],
    "category": ["apple", "banana", "cherry", "date", "elderberry"]
})

df = df.cast({"category" : pl.Categorical})

path_to_delta_table = "Path_to_delta_table"
df.write_delta(path_to_delta_table)

#re-read the table

df_new = pl.read_delta(path_to_delta_table) # errors out

Log output

---------------------------------------------------------------------------
SchemaError                               Traceback (most recent call last)
Cell In[28], line 15
     11 df.write_delta(path_to_delta_table)
     13 #re-read the table
---> 15 df_new = pl.read_delta(path_to_delta_table) # errors out

File /usr/local/lib/python3.9/site-packages/polars/io/delta.py:149, in read_delta(source, version, columns, rechunk, storage_options, delta_table_options, use_pyarrow, pyarrow_options)
    147 if columns is not None:
    148     df = df.select(columns)
--> 149 return df.collect()

File /usr/local/lib/python3.9/site-packages/polars/lazyframe/frame.py:2029, in LazyFrame.collect(self, type_coercion, predicate_pushdown, projection_pushdown, simplify_expression, slice_pushdown, comm_subplan_elim, comm_subexpr_elim, cluster_with_columns, collapse_joins, no_optimization, streaming, engine, background, _eager, **_kwargs)
   2027 # Only for testing purposes
   2028 callback = _kwargs.get("post_opt_callback", callback)
-> 2029 return wrap_df(ldf.collect(callback))

SchemaError: dtypes differ for column category: Dictionary(UInt32, Utf8View, false) != Utf8View

Issue description

This issue was observed in 1.16 and still exists in 1.18.
I can confirm this that it did not exists till 1.12 version.

Expected behavior

Table read operation should be successful. If possible, the data schema should reflect those columns as categorical instead of string columns.

Installed versions

--------Version info---------
Polars:              1.16.0
Index type:          UInt32
Platform:            Linux-6.8.0-49-generic-x86_64-with-glibc2.36
Python:              3.9.21 (main, Dec  4 2024, 20:35:10) 
[GCC 12.2.0]
LTS CPU:             False

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               4.2.2
boto3                1.28.64
cloudpickle          3.0.0
connectorx           <not installed>
deltalake            0.21.0
fastexcel            <not installed>
fsspec               2024.6.1
gevent               <not installed>
google.auth          <not installed>
great_tables         <not installed>
matplotlib           3.8.4
nest_asyncio         1.6.0
numpy                1.23.5
openpyxl             <not installed>
pandas               1.1.3
pyarrow              16.0.0
pydantic             2.7.4
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                2.3.1+cu118
xlsx2csv             <not installed>
xlsxwriter           3.2.0
@SidPharVision SidPharVision added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

1 participant