{"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/68506541d2de983056c9eb244e1ea05fab377dfc/crates/polars-arrow/src/io/ipc/write/common.rs#L138-L174","documentation":"Documented panic of encode_dictionary: the array passed is not a DictionaryArray, so its keys/values cannot be dictionary-encoded for IPC. This is an internal dispatch error — the caller must downcast to DictionaryArray before calling encode_dictionary.","triggerScenarios":"This panic/expect fires when execution reaches an unguarded state described by: \"Given array is not a DictionaryArray\". 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.","commonSituations":"Encountered when input data or configuration does not meet the preconditions of the throwing code path (\"Given array is not a DictionaryArray\"). 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.","solutions":["Pass a DictionaryArray to the dictionary-IPC write path; downcast the array to DictionaryArray before calling.","If the column is categorical, ensure it is represented as a dictionary-encoded Arrow array before writing."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"68506541d2de983056c9eb244e1ea05fab377dfc","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}