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

allow_missing_columns combined with passing schema fails if columns are missing from first file #19081

Closed
2 tasks done
aersam opened this issue Oct 3, 2024 · 1 comment · Fixed by #19084
Closed
2 tasks done
Assignees
Labels
A-io-parquet Area: reading/writing Parquet files accepted Ready for implementation bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@aersam
Copy link

aersam commented Oct 3, 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

import polars as pl

schema = {"UserId": pl.Int64, "FirstName": pl.String}
pl.DataFrame({"UserId": [1555], "FirstName": ["Peter"]}).write_parquet("test1.parquet")
pl.DataFrame({"UserId": [1556]}).write_parquet("test2.parquet")
print(
    pl.scan_parquet("test2.parquet", schema=schema, allow_missing_columns=True)
    .select(pl.col("FirstName"), pl.col("UserId"))
    .collect()
)

Log output

Traceback (most recent call last):
  File "C:\Projects\BMS_Github\deltalake2db\repo.py", line 9, in <module>
    .collect()
     ^^^^^^^^^
  File "C:\Projects\BMS_Github\deltalake2db\.venv\Lib\site-packages\polars\lazyframe\frame.py", line 2050, in collect
    return wrap_df(ldf.collect(callback))
                   ^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.ColumnNotFoundError: FirstName

Resolved plan until failure:

        ---> FAILED HERE RESOLVING 'select' <---
Parquet SCAN [test2.parquet]
PROJECT */1 COLUMNS

Issue description

As I pass the column Name "FirstName" in the schema and set allow_missing_columns to true, I would also expect it to work. However I get this ColumnNotFoundError

Expected behavior

First Name should be Null. Feature was introduced in this PR: #18922

Installed versions

Polars:              1.9.0
Index type:          UInt32
Platform:            Windows-10-10.0.19045-SP0
Python:              3.11.1 (tags/v3.11.1:a7a450f, Dec  6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)]

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            0.18.1
fastexcel            <not installed>
fsspec               2024.9.0
gevent               <not installed>
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         <not installed>
numpy                2.1.1
openpyxl             <not installed>
pandas               2.2.3
pyarrow              17.0.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           <not installed>
@aersam aersam added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Oct 3, 2024
@etiennebacher
Copy link

etiennebacher commented Oct 3, 2024

I think allow_missing_columns only works in cases where you scan multiple files at once, here you only scan one.

Edit: using ["test1.parquet", "test2.parquet"]:

shape: (2, 2)
┌───────────┬────────┐
│ FirstName ┆ UserId │
│ ---       ┆ ---    │
│ str       ┆ i64    │
╞═══════════╪════════╡
│ Peter     ┆ 1555   │
│ null      ┆ 1556   │
└───────────┴────────┘

@nameexhaustion nameexhaustion added accepted Ready for implementation P-medium Priority: medium A-io-parquet Area: reading/writing Parquet files and removed needs triage Awaiting prioritization by a maintainer labels Oct 3, 2024
@nameexhaustion nameexhaustion self-assigned this Oct 3, 2024
@nameexhaustion nameexhaustion changed the title allow_missing_columns not really working allow_missing_columns combined with passing schema fails if columns are missing from first file Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io-parquet Area: reading/writing Parquet files accepted Ready for implementation bug Something isn't working P-medium Priority: medium python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants