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

from_any_values_and_dtype converts AnyValue::Struct to null #18800

Open
2 tasks done
i64 opened this issue Sep 18, 2024 · 0 comments · May be fixed by #18801
Open
2 tasks done

from_any_values_and_dtype converts AnyValue::Struct to null #18800

i64 opened this issue Sep 18, 2024 · 0 comments · May be fixed by #18801
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars

Comments

@i64
Copy link

i64 commented Sep 18, 2024

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

use std::io::Cursor;

use polars::prelude::*;

const BASIC_JSON: &str = r#"
{"user": {"name": "test1"}, "id": 1}
{"user": {"name": "test2"}, "id": 2}
"#;

fn main() {
    let file = Cursor::new(BASIC_JSON);

    let df = dbg!(JsonReader::new(file)
        .with_json_format(JsonFormat::JsonLines)
        .finish()
        .unwrap());
    // shape: (2, 2)
    // ┌───────────┬─────┐
    // │ user      ┆ id  │
    // │ ---       ┆ --- │
    // │ struct[1] ┆ i64 │
    // ╞═══════════╪═════╡
    // │ {"test1"} ┆ 1   │
    // │ {"test2"} ┆ 2   │
    // └───────────┴─────┘

    let test_row = dbg!(df.get_row(0).unwrap());
    // Row(
    //     [
    //         Struct(
    //             0,
    //             StructArray[{name: [116, 101, 115, 116, 49]}, {name: [116, 101, 115, 116, 50]}],
    //             [
    //                 Field {
    //                     name: "name",
    //                     dtype: String,
    //                 },
    //             ],
    //         ),
    //         Int64(
    //             1,
    //         ),
    //     ],
    // )

    dbg!(DataFrame::from_rows(&[test_row]));
    // shape: (1, 2)
    // ┌───────────┬──────────┐
    // │ column_0  ┆ column_1 │
    // │ ---       ┆ ---      │
    // │ struct[1] ┆ i64      │
    // ╞═══════════╪══════════╡
    // │ {null}    ┆ 1        │
    // └───────────┴──────────┘,
}

Log output

No response

Issue description

The function Series::from_any_values_and_dtype assumes all DataType::Struct type holds AnyValue::StructOwned, and dismisses the AnyValue::Struct type and it returns null.

DataType::Struct(fields) => any_values_to_struct(values, fields, strict)?,

AnyValue::StructOwned(payload) => {

_ => {
has_outer_validity = true;
field_avs.push(AnyValue::Null)
},

Expected behavior

not returning null and handling the AnyValue::Struct type

Installed versions

0.43.1

@i64 i64 added bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant