Giter VIP home page Giter VIP logo

Comments (6)

mcrumiller avatar mcrumiller commented on June 17, 2024 1

Ok, I've find the final reason. This file is not a UTF-8 file, it is a "MS932", "CP932" or "Windows-31J", often called "Shift-JIS". You can see that standard utf8 decoding in python fails:

>>> b = b'\xe3\x82\xa8\xe3\x83\xad\xe4\xba\x8b\xe5\xb8\xab\xe3\x81\x9f\xe3\x81\xa1\xe3\x82\x88\xe3\x82\x8a \xe4\xba\xba\xe9\xa1\x9e\xe5\xad\xa6\xe5\x85\xa5\xe9\x96'
>>> b.decode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 37-38: unexpected end of data

But if we specify Shift-JIS it works:

>>> b.decode("Shift-JIS")
'繧ィ繝ュ莠句クォ縺溘■繧医j 莠コ鬘槫ュヲ蜈・髢'

I'm not sure if it's intended to be unicode and simply has some bad encoding, or if it was mis-encoded, but the TL;DR is that polars doesn't support this encoding if it is indeed Shift-JIS, sorry!

from polars.

elisevansbbfc avatar elisevansbbfc commented on June 17, 2024

The relevant data can be found here. I am using the title.akas.tsv.gz data.

from polars.

avimallu avatar avimallu commented on June 17, 2024

As an FYI, this has nothing to do with unidecode. Performing just a title_akas_df.get_column("title").to_list() can reproduce the issue. Could you please create that as a minimal example instead?

from polars.

mcrumiller avatar mcrumiller commented on June 17, 2024

The issue occurs because of line 467,864. If we load into df then we can see:

>>> df = pl.read_csv(
...    "title.akas.tsv",
...     separator="\t",
...     dtypes={"title": str},
...     ignore_errors=True,
... )
>>> df["title"][467862]
'人類學入門'
>>> df["title"][467863]
pyo3_runtime.PanicException: Python API call failed

The issue is that the string cannot be rendered, and has nothing to do with map_elements or lists.

If we cast to binary, we get:

>>> df["title"].cast(pl.Binary)[467863]
b'\xe3\x82\xa8\xe3\x83\xad\xe4\xba\x8b\xe5\xb8\xab\xe3\x81\x9f\xe3\x81\xa1\xe3\x82\x88\xe3\x82\x8a \xe4\xba\xba\xe9\xa1\x9e\xe5\xad\xa6\xe5\x85\xa5\xe9\x96'

Perhaps someone with unicode experience can decipher this. If we try to grab just that one row with a selection, we panic and python is killed:

>>> s = df.select(pl.col("title").filter(pl.int_range(pl.len()) == 467863))
thread '<unnamed>' panicked at library/core/src/panicking.rs:155:5:
unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached
thread caused non-unwinding panic. aborting.
Aborted

from polars.

mcrumiller avatar mcrumiller commented on June 17, 2024

FYI the space in the byte array seen above is \x20. There is some badly formed unicode in here.

from polars.

mcrumiller avatar mcrumiller commented on June 17, 2024

Also, it's not your fault, the IMDB Page specifically cites Utf-8 as the encoding, but they are just wrong. I'd maybe contact them if you really need this dataset, or you can create a workaround by re-exporting the file with that one record deleted.

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.