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

write_parquet does not preserve enum categories for empty data frames #20083

Closed
2 tasks done
borchero opened this issue Dec 1, 2024 · 0 comments · Fixed by #20181
Closed
2 tasks done

write_parquet does not preserve enum categories for empty data frames #20083

borchero opened this issue Dec 1, 2024 · 0 comments · Fixed by #20181
Assignees
Labels
accepted Ready for implementation bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@borchero
Copy link
Contributor

borchero commented Dec 1, 2024

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

For an empty data frame, writing to and reading from a parquet file turns enums into categoricals.

import polars as pl

df = pl.DataFrame(schema={"a": pl.Enum(["a", "b", "c"])})
df
# shape: (0, 1)
# ┌──────┐
# │ a    │
# │ ---  │
# │ enum │
# ╞══════╡
# └──────┘

df.write_parquet("out.parquet")
df_new = pl.read_parquet("out.parquet")
df_new
# shape: (0, 1)
# ┌─────┐
# │ a   │
# │ --- │
# │ cat │
# ╞═════╡
# └─────┘

df_new.schema
# Schema({'a': Categorical(ordering='physical')})

The same does not happen for non-empty data frames:

import polars as pl

df = pl.DataFrame({"a": ["a"]}, schema={"a": pl.Enum(["a", "b", "c"])})
df
# shape: (1, 1)
# ┌──────┐
# │ a    │
# │ ---  │
# │ enum │
# ╞══════╡
# │ a    │
# └──────┘

df.write_parquet("out.parquet")
df_new = pl.read_parquet("out.parquet")
df_new
# shape: (1, 1)
# ┌──────┐
# │ a    │
# │ ---  │
# │ enum │
# ╞══════╡
# │ a    │
# └──────┘

df_new.schema
# Schema({'a': Enum(categories=['a', 'b', 'c'])})

Log output

No response

Issue description

See above.

Expected behavior

The expected behavior would be to preserve the enum information even when empty data frames are written to parquet.

Installed versions

--------Version info---------
Polars:              1.16.0
Index type:          UInt32
Platform:            macOS-14.6.1-arm64-arm-64bit-Mach-O
Python:              3.13.0 | packaged by conda-forge | (main, Nov 27 2024, 19:18:26) [Clang 18.1.8 ]
LTS CPU:             False

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
boto3                <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            <not installed>
fastexcel            <not installed>
fsspec               <not installed>
gevent               <not installed>
google.auth          <not installed>
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         <not installed>
numpy                2.1.3
openpyxl             <not installed>
pandas               <not installed>
pyarrow              <not installed>
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@borchero borchero added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Dec 1, 2024
@c-peters c-peters added the accepted Ready for implementation label Dec 8, 2024
@github-project-automation github-project-automation bot moved this to Ready in Backlog Dec 8, 2024
@c-peters c-peters moved this from Ready to Done in Backlog Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants