-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
polars.read_json fails when reading empty list from json response #7355
Comments
Incase it's relevant, I just ran into a similar sort of issue: #6745 I found It returns
|
I'm not sure if it's related but there is also a problem with empty lists in rust code: //!
//! ```cargo
//! [dependencies]
//! polars = { version = "0.36.2", features = ["json"] }
//! ```
use polars::prelude::*;
fn main() {
let f = std::io::Cursor::new("[]");
let df = JsonReader::new(f).finish();
println!("{:?}", df);
} output:
|
I had the same problem in Rust, checking if the JSON is empty before calling |
Polars version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of Polars.
Issue description
Noticed this was addressed in a recent fix for read_ndjson but seems to have slipped through on read_json.
polars.read_json fails when the response is empty, seems as if the parser doesn't know what to to do in this case and returns the following error BindingsError:"ArrowError(NotYetImplemented("read an Array from a non-Array data type"))"
May be a bit of an edge case but is somewhat of an issue when dealing with json responses from http requests that show 200 but give an empty body. Currently circumvent it by passing the response via json.loads (well orjson given it's improvements vs stdlib json) to a DataFrame constructor i.e. as shown below. Feel the read_json should be able to handle this
Getting deeper and deeper into Rust out of personal interest, so will try and submit a pull request to fix myself if I get the time - but realise this may be a trivial handle for someone else
Reproducible example
Expected behavior
Would expect this simply to output to an empty DataFrame
Installed versions
The text was updated successfully, but these errors were encountered: