{"record":{"id":"6d0deac905426426","repo":"pola-rs/polars","slug":"expected-statistics-to-be-found-instead","errorCode":null,"errorMessage":"Expected Statistics to be {}, found {} instead","messagePattern":"Expected Statistics to be (.+?), found (.+?) instead","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-parquet/src/parquet/statistics/mod.rs","lineNumber":188,"sourceCode":"                }\n\n                #[doc = concat!(\"Try to take [`Statistics`] as [`\", stringify!($struct), \"`]\")]\n                #[inline]\n                pub fn $into_ident(self) -> Option<$struct> {\n                    match self {\n                        Self::$variant(s) => Some(s),\n                        _ => None,\n                    }\n                }\n\n                #[doc = concat!(\"Interpret [`Statistics`] to be [`\", stringify!($struct), \"`]\")]\n                ///\n                /// Panics if it is not the correct variant.\n                #[track_caller]\n                #[inline]\n                pub fn $expect_ident(&self) -> &$struct {\n                    let Self::$variant(s) = self else {\n                        panic!(\"Expected Statistics to be {}, found {} instead\", stringify!($struct), self.variant_str());\n                    };\n\n                    s\n                }\n\n                #[doc = concat!(\"Interpret [`Statistics`] to be [`\", stringify!($struct), \"`]\")]\n                ///\n                /// Panics if it is not the correct variant.\n                #[track_caller]\n                #[inline]\n                pub fn $owned_expect_ident(self) -> $struct {\n                    let Self::$variant(s) = self else {\n                        panic!(\"Expected Statistics to be {}, found {} instead\", stringify!($struct), self.variant_str());\n                    };\n\n                    s\n                }\n            )+","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-parquet/src/parquet/statistics/mod.rs#L170-L206","documentation":"Generated accessor (e.g. expect_binary, expect_int) on the parquet Statistics enum panics when the actual statistics variant differs from the expected one. This is a caller-side type assertion; the message names the expected struct and the found variant.","triggerScenarios":"Calling stats.expect_int() (or similar expect_* / owned expect_*) on Statistics holding e.g. BooleanStatistics instead.","commonSituations":"Code assuming uniform column types in a parquet file; reading metadata for a column whose logical type differs from what the handler expects; refactors that changed column types.","solutions":["Match on the Statistics enum and handle each variant explicitly","Check the column's physical/logical type before calling expect_*","Use the variant_str()/display API instead of asserting a fixed variant"],"exampleFix":"// before\nlet s = stats.expect_int().min;\n// after\nif let Statistics::Int(s) = &stats { use s.min } else { handle other variant }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Rust narrowing\nfn as_int_stats(s: &Statistics) -> Option<&IntStatistics> {\n    match s { Statistics::Int(i) => Some(i), _ => None }\n}","tryCatchPattern":"std::panic::catch_unwind(|| stats.expect_int());","preventionTips":["Prefer matching on the Statistics enum over expect_* accessors","Consult the column's logical type from schema before reading stats","Handle heterogeneous columns generically"],"tags":["parquet","statistics","type-mismatch","panic"],"backgroundTag":"type-mismatch","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"}