Giter VIP home page Giter VIP logo

Comments (7)

orlp avatar orlp commented on September 24, 2024 1

@nameexhaustion Sorry I just read ritchie's comment and closed based on that. We do need to ensure we only generate valid UTF-8.

from polars.

orlp avatar orlp commented on September 24, 2024 1

@pj-ml Perhaps, but that is not a P-high Priority: high bug. If the fix for this doesn't cover that I'd separate it into a separate bug/enhancement.

from polars.

ritchie46 avatar ritchie46 commented on September 24, 2024

I believe that's not a proper encoded csv file. Quotes must be escaped with quotes. Polars follows https://www.ietf.org/rfc/rfc4180.txt. Anything that doesn't follow that spec, we don't read. Though the error must be better.

from polars.

pj-ml avatar pj-ml commented on September 24, 2024

f.write('col1\n""• ') with a space appended to the end parses fine though

from polars.

pj-ml avatar pj-ml commented on September 24, 2024

I read https://www.ietf.org/rfc/rfc4180.txt and I see that if double quotes are used inside the entry, the entry must be encapsulated by double quotes too.

I think we can close this out then. I will just have to use use_pyarrow=True since I receive files that do not follow the standard used by polars.

from polars.

nameexhaustion avatar nameexhaustion commented on September 24, 2024

@orlp There could actually be an issue here - using read_csv polars will create a dataframe containing invalid Utf8 instead of immediately failing, see an example here:

import polars as pl

df = pl.read_csv('col1\n""•'.encode())  # this loads a dataframe without complaining

print(df.select(pl.all().cast(pl.Binary)))
# ┌─────────────┐
# │ col1        │
# │ ---         │
# │ binary      │
# ╞═════════════╡
# │ b"\xe2\x80" │
# └─────────────┘
print(df.select(pl.all().cast(pl.Binary).cast(pl.String)))  # casting it to binary and then back to run utf-8 validation to show that validation fails
# polars.exceptions.ComputeError: invalid utf8
print(df)  # printing will cause a panic due to invalid utf-8
# thread '<unnamed>' panicked at crates/polars-core/src/fmt.rs:393:21:
# byte index 34 is out of bounds of `�`

from polars.

pj-ml avatar pj-ml commented on September 24, 2024

And how about cases where it generates valid UTF-8, but the input file does not follow the standard? Shouldn't there at least be a warning in such a case?

See example (no errors and no warnings):

import polars as pl

df = pl.read_csv('col1\n""• '.encode())

print(df.select(pl.all().cast(pl.Binary).cast(pl.String)))
# shape: (1, 1)
# ┌──────┐
# │ col1 │
# │ ---  │
# │ str  │
# ╞══════╡
# │ •    │
# └──────┘

from polars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.