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

Fix overwrite of dtypes for DF.load_csv/2 #955

Merged
merged 2 commits into from
Aug 1, 2024
Merged

Conversation

philss
Copy link
Member

@philss philss commented Aug 1, 2024

Using the with_schema function does not work correctly because Polars expects to receive all column names, and with the correct order. We are passing a map to the backend, and then we transform that to a list before calling the Rust code. So the schema could be out-of-order.

We are now using with_schema_overwrite for both load_csv and from_csv.

Closes #953

Using the `with_schema` function does not correctly because expects to
receive all column names, and with the correct order. We are passing a
map to the backend, and then we transform that to a list before calling
the Rust code. So the schema could be out-of-order.

We are now using `with_schema_overwrite` for both `load_csv` and
`from_csv`.

Closes #953
let read_options = if dtypes.is_empty() {
CsvReadOptions::default()
} else {
CsvReadOptions::default().with_schema_overwrite(Some(schema_from_dtypes_pairs(dtypes)?))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of a conditional, we could have schema_from_dtypes_pairs return Some/None accordingly, and we always call with_schema_overwrite?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! I changed in 8460170

@philss philss merged commit e6638a0 into main Aug 1, 2024
4 checks passed
@philss philss deleted the ps-fix-load-csv-dtypes branch August 1, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Orders of names after CSV loading seems buggy since 9.0
2 participants