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

feat(rust, python): add truncate_ragged_lines #10660

Merged
merged 3 commits into from
Aug 22, 2023
Merged

feat(rust, python): add truncate_ragged_lines #10660

merged 3 commits into from
Aug 22, 2023

Conversation

ritchie46
Copy link
Member

@ritchie46 ritchie46 commented Aug 22, 2023

closes #10585

@ritchie46 ritchie46 marked this pull request as draft August 22, 2023 06:11
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Aug 22, 2023
@ritchie46 ritchie46 marked this pull request as ready for review August 22, 2023 06:31
@Wainberg
Copy link
Contributor

I raised the initial issue (#10585). I really like how this pull request causes an error to be raised when reading a ragged CSV, instead of silently truncating the ragged columns.

However, I disagree with the need for a truncate_ragged_lines argument, because it doesn't seem like a common use case to want to lop off part of your file before reading it.

Instead, I'd suggest allowing the user to set new_columns to be longer than the number of columns in the first line. This would make polars consistent with pandas, as illustrated here.

Then, the error message that's raised when reading a ragged CSV could recommend one of two solutions:

  1. setting infer_schema_length=None to parse ragged data with no issues, at a potentially large runtime cost; or
  2. setting new_columns to be as long as needed to encompass all the ragged columns.

@ritchie46
Copy link
Member Author

ritchie46 commented Aug 22, 2023

However, I disagree with the need for a truncate_ragged_lines argument, because it doesn't seem like a common use case to want to lop off part of your file before reading it.

You don't have to use it

Instead, I'd suggest allowing the user to set new_columns to be longer than the number of columns in the first line. This would make polars consistent with pandas, as illustrated #10585 (comment).

Polars needs a schema. New columns is a rename after the fact. The argument is only for renaming columns in the csv-file. I don't want this control anything else.

@ritchie46 ritchie46 merged commit dc2e617 into main Aug 22, 2023
24 of 25 checks passed
@ritchie46 ritchie46 deleted the ragged_lines branch August 22, 2023 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pl.read_csv() inconsistently handles ragged CSVs, sometimes silently truncating data
2 participants