pola-rs/polars · error

Writing {:?} to JSON

Error message

Writing {:?} to JSON

What it means

todo!() in polars-json serialization dispatch: the array's ArrowDataType has no JSON serializer implemented in this build, so writing it to JSON cannot proceed. Signals unsupported functionality for that dtype, not invalid data.

Source

Thrown at crates/polars-json/src/json/write/serialize.rs:634

                convert,
                offset,
                take,
            )
        },
        ArrowDataType::Time64(tu) => {
            let convert = match tu {
                TimeUnit::Nanosecond => time64ns_to_time,
                tu => panic!("Invalid time unit '{tu:?}' for Time."),
            };
            time_serializer(
                array.as_any().downcast_ref().unwrap(),
                convert,
                offset,
                take,
            )
        },
        ArrowDataType::Null => null_serializer(array.len(), offset, take),
        other => todo!("Writing {:?} to JSON", other),
    }
}

fn serialize_item<'a>(
    buffer: &mut Vec<u8>,
    record: impl Iterator<Item = (&'a str, &'a [u8])>,
    is_first_row: bool,
) {
    if !is_first_row {
        buffer.push(b',');
    }
    buffer.push(b'{');
    let mut first_item = true;
    for (key, value) in record {
        if !first_item {
            buffer.push(b',');
        }
        first_item = false;

View on GitHub (pinned to 9b5d73fd00)

Solutions

  1. JSON writing is not implemented for this dtype; cast the column to a supported type (string/numeric) before serializing.
  2. Convert nested/unsupported values to strings before writing JSON.
Defensive patterns

Strategy: fallback

When it happens

Trigger: This panic/expect fires when execution reaches an unguarded state described by: "Writing {:?} to JSON". Typical triggers: unsupported dtype or feature-gated code path reached at runtime, invalid user input or environment variable value, calling API methods in the wrong order or on mismatched types, or data (lengths, offsets, ranges) violating the function's preconditions.

Common situations: Encountered when input data or configuration does not meet the preconditions of the throwing code path ("Writing {:?} to JSON"). Common cases: missing Cargo feature flags, mismatched dtypes/lengths between arrays or series, out-of-range temporal values, malformed environment variables, or operations on unsupported/complex nested types.


AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19). Data as JSON: /api/errors/41cdfa4535d9c924. Report an issue: GitHub.