alphydan

alphydan

Hello,

I’m an elixir beginner, exploring livebook. I’m running a local notebook on a linux machine. Initially I tried to import a CSV file with Explorer like so:

alias Explorer.{DataFrame, Series}
path_to_csv = "./some_file.csv"
DataFrame.from_csv!(path_to_csv)

However, I am seeing the following error:

** (RuntimeError) from_csv failed: {:polars, "Could not parse `Fee Amount` 
    as dtype Int64 at column 16.\nThe current offset in the file is 249 bytes.\n\n
    Consider specifying the correct dtype, increasing\n
    the number of records used to infer the schema,\n
    enabling the `ignore_errors` flag, or adding\n`Fee Amount` to the `null_values` list."}
    (explorer 0.5.5) lib/explorer/data_frame.ex:438: Explorer.DataFrame.from_csv!/2

To check if the problem was indeed with the data in the column Fee Amount, I filled the column with integers. But I get the same error. What can I try to better diagnose this problem?

Showing Posts 1 to 10

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hi @alphydan welcome! Are you able to provide a sample of that CSV file?

BradS2S

BradS2S

You can use :dtype to explicitly set the data type for a column instead of letting it try to infer it.

al2o3cr

al2o3cr

One small thing that jumps out:

Could not parse Fee Amount as dtype Int64 at column 16.
The current offset in the file is 249 bytes.

This sounds like it’s on at least the second line of the file, and so should be data

That’s a reference to the with_null_values setting in polars_io::csv::CsvReader, which is intended to parse values like "n/a" to null.

The message suggests that the reader found the literal string “Fee Amount” where it expected data.

:thinking: what was a header-shaped value like “Fee Amount” doing on the second line of a CSV?

alphydan

alphydan OP

@BradS2S @benwilson512 @al2o3cr Thank you for all your suggestions. “Fee Amount” was not on the second line, but on the header (first row).

A potential problem with the header led me to try changing all headers to the format something_or_the_other instead of Something Or \n the Other.

I found that it failed when I had a return character inside the header. The CSV gets imported correctly now. Thank you for the prompt replies.

LostKobrakai

LostKobrakai

Were these quoted? If no, then that’s indeed invalid. If they were, then this sounds like a but in the csv parser.

alphydan

alphydan OP

Ok, here’s an example to further diagnose the problem:

Running $ cat -v example_failing.csv in the terminal shows:

"Timestamp$
(ISO)",Animal Type,Animal Color,"Friends of$
Given Animal","Another$
Timestamp$
(ISO)",Feedstock,"Favorite food$
for Animal",Feed Amount,Feed Frequency^M$
2023,Tiger,Yellow,Lion,2023-03-14,3,meat,32.2,weekly^M$
2023,Tiger,Yellow,Lion,2023-03-14,3,meat,32.2,weekly

(Where $ corresponds to \n or Unix line endings). Trying to import it in livebook:

path_to_csv = "./example_failing.csv"
IO.puts(path_to_csv)
DataFrame.from_csv!(path_to_csv)

leads to this error:

** (RuntimeError) from_csv failed: {:polars, "Could not parse `(ISO)\"` as dtype Int64 at column 1.\n
The current offset in the file is 11 bytes.\n\n

Consider specifying the correct dtype, increasing\n
the number of records used to infer the schema,\n
enabling the `ignore_errors` flag, or adding
\n`(ISO)\"` to the `null_values` list."}
    (explorer 0.5.5) lib/explorer/data_frame.ex:438: Explorer.DataFrame.from_csv!/2
BradS2S

BradS2S

Remove all the new line characters from the column headers.

LostKobrakai

LostKobrakai

That sounds like a bug / missing implementation in the parser of polars then. LF or CRLF are supposed to be allowed in quoted fields based on RFC 4180.

alphydan

alphydan OP

Removing all return characters leads to an import without errors.

"Timestamp (ISO)",Animal Type,Animal Color,"Friends of Given Animal","Another Timestamp (ISO)",Feedstock,"Favorite food for Animal",Feed Amount,Feed Frequency^M
2023,Tiger,Yellow,Lion,2023-03-14,3,meat,32.2,weekly^M
2023,Tiger,Yellow,Lion,2023-03-14,3,meat,32.2,weekly

is imported correctly. Does that mean that return characters are not allowed in headers, even with quotes?

return characters outside the header seem to be imported correctly. for example, if I have an element of the csv be Tiger and \nBeasts, but no returns in the header I can see:

  Polars[2 x 9]
  Timestamp (ISO) integer [2023, 2023]
  Animal Type string ["Tiger and \nBeasts", "Tiger"]
  Animal Color string ["Yellow", "Yellow"]
  Friends of Given Animal string ["Lion", "Lion"]
  Another Timestamp (ISO) string ["2023-03-14", "2023-03-14"]
  Feedstock integer [3, 3]
  Favorite food for Animal string ["meat", "meat"]
  Feed Amount float [32.2, 32.2]
  Feed Frequency string ["weekly", "weekly"]
``
BradS2S

BradS2S

Yes you want it on a single line. That parsing error means they don’t expect labels to be on more than one line

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews