{"record":{"id":"bb5634d318c3dd3a","repo":"pola-rs/polars","slug":"given-array-is-not-a-dictionaryarray","errorCode":null,"errorMessage":"Given array is not a DictionaryArray","messagePattern":"Given array is not a DictionaryArray","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-arrow/src/io/ipc/write/common.rs","lineNumber":156,"sourceCode":"            let values = array.as_any().downcast_ref::<MapArray>().unwrap().field();\n            let field = field.fields.first().ok_or_else(|| polars_err!(ComputeError: \"Invalid IPC field structure: expected nested field but fields vector is empty\"))?;\n            dictionaries_to_encode(field, values.as_ref(), dictionary_tracker, dicts_to_encode)\n        },\n    }\n}\n\n/// Encode a dictionary array with a certain id.\n///\n/// # Panics\n///\n/// This will panic if the given array is not a [`DictionaryArray`].\npub fn encode_dictionary(\n    dict_id: i64,\n    array: &dyn Array,\n    options: &WriteOptions,\n) -> PolarsResult<EncodedData> {\n    let PhysicalType::Dictionary(key_type) = array.dtype().to_physical_type() else {\n        panic!(\"Given array is not a DictionaryArray\")\n    };\n\n    match_integer_type!(key_type, |$T| {\n        let array: &DictionaryArray<$T> = array.as_any().downcast_ref().unwrap();\n\n        encode_dictionary_values(dict_id, array.values().as_ref(), options)\n    })\n}\n\npub fn encode_new_dictionaries(\n    field: &IpcField,\n    array: &dyn Array,\n    options: &WriteOptions,\n    dictionary_tracker: &mut DictionaryTracker,\n    encoded_dictionaries: &mut Vec<EncodedData>,\n) -> PolarsResult<()> {\n    let mut dicts_to_encode = Vec::new();\n    dictionaries_to_encode(field, array, dictionary_tracker, &mut dicts_to_encode)?;","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-arrow/src/io/ipc/write/common.rs#L138-L174","documentation":"encode_dictionary downcasts the given array to DictionaryArray and panics if the downcast fails. It fires when the dictionary-tracking logic is handed an array whose physical type is not a DictionaryArray — typically a nested array child passed by mistake during IPC dictionary encoding.","triggerScenarios":"Thrown at crates/polars-arrow/src/io/ipc/write/common.rs:156 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure only DictionaryArray columns are routed to encode_dictionary","Check the schema-to-dict-id mapping so nested fields resolve to the correct dictionary arrays","Guard the downcast and return a PolarsError instead of panicking"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}