{"record":{"id":"604e2035f3bbf67d","repo":"pola-rs/polars","slug":"can-only-convert-date-datetime-to-naivetime","errorCode":null,"errorMessage":"can only convert date/datetime to NaiveTime","messagePattern":"can only convert date/datetime to NaiveTime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/chunked_array/temporal/conversion.rs","lineNumber":32,"sourceCode":"            #[cfg(feature = \"dtype-date\")]\n            AnyValue::Date(v) => date32_to_datetime(*v),\n            #[cfg(feature = \"dtype-datetime\")]\n            AnyValue::Datetime(v, tu, _) => match tu {\n                TimeUnit::Nanoseconds => timestamp_ns_to_datetime(*v),\n                TimeUnit::Microseconds => timestamp_us_to_datetime(*v),\n                TimeUnit::Milliseconds => timestamp_ms_to_datetime(*v),\n            },\n            _ => panic!(\"can only convert date/datetime to NaiveDateTime\"),\n        }\n    }\n}\n\nimpl From<&AnyValue<'_>> for NaiveTime {\n    fn from(v: &AnyValue) -> Self {\n        match v {\n            #[cfg(feature = \"dtype-time\")]\n            AnyValue::Time(v) => time64ns_to_time(*v),\n            _ => panic!(\"can only convert date/datetime to NaiveTime\"),\n        }\n    }\n}\n\n// Used by lazy for literal conversion\npub fn datetime_to_timestamp_ns(v: NaiveDateTime) -> i64 {\n    let us = v.and_utc().timestamp() * 1_000_000_000; //nanos\n    us + v.and_utc().timestamp_subsec_nanos() as i64\n}\n\npub fn datetime_to_timestamp_ms(v: NaiveDateTime) -> i64 {\n    v.and_utc().timestamp_millis()\n}\n\npub fn datetime_to_timestamp_us(v: NaiveDateTime) -> i64 {\n    let us = v.and_utc().timestamp() * 1_000_000;\n    us + v.and_utc().timestamp_subsec_micros() as i64\n}","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/crates/polars-core/src/chunked_array/temporal/conversion.rs#L14-L50","documentation":"Panic in From<&AnyValue> for NaiveTime: the AnyValue variant is not a Time (or Datetime whose time component is taken); the value cannot be interpreted as a time of day. Match on the variant or extract the time explicitly.","triggerScenarios":"This panic/expect fires when execution reaches an unguarded state described by: \"can only convert date/datetime to NaiveTime\". 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 (\"can only convert date/datetime to NaiveTime\"). 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":["Convert only Date/Datetime/Time columns to NaiveTime as supported; verify the dtype first.","Cast to Time or Datetime before extracting the NaiveTime."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}