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(python): provide better errors when failing to read CSV data from buffers that have advanced their read position #6920

Merged
merged 1 commit into from
Feb 16, 2023

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Feb 16, 2023

Ref: #6875.

The above PR inadvertently introduced a breaking change when reading CSV data from StringIO buffers. This patch doesn't undo that change, but instead significantly improves the errors raised when the breaking behaviour is triggered:

Example:

from io import StringIO
import polars as pl

s = StringIO("a,b\n1,2")
df1 = pl.read_csv(s, dtypes=[pl.Int32,pl.Float64])

# reading "s" again blows up (it didn't before),
# as the buffer's read position has been advanced
df2 = pl.read_csv(s, dtypes=[pl.Int8,pl.Float32])

Before: (raises a basic error)

# NoDataError: empty csv

After: (still raises, but now provides much more context as to why...)

# NoDataError: empty CSV data from StringIO (buffer position = 7; try seek(0) before reading?)

…m buffers that have advanced their read position
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Feb 16, 2023
@ritchie46 ritchie46 merged commit 410b571 into pola-rs:master Feb 16, 2023
@alexander-beedie alexander-beedie deleted the clarify-io-error branch February 16, 2023 10:30
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants