Jack Wright ae54d05930
Upgrade to polars 0.43 (#14148)
Upgrades the polars plugin to polars version 0.43
2024-10-23 19:14:24 +02:00

33 lines
1.1 KiB
Rust

use nu_protocol::{FromValue, ShellError, Value};
use polars::prelude::PlSmallStr;
pub fn extract_strings(value: Value) -> Result<Vec<String>, ShellError> {
let span = value.span();
match (
<String as FromValue>::from_value(value.clone()),
<Vec<String> as FromValue>::from_value(value),
) {
(Ok(col), Err(_)) => Ok(vec![col]),
(Err(_), Ok(cols)) => Ok(cols),
_ => Err(ShellError::IncompatibleParametersSingle {
msg: "Expected a string or list of strings".into(),
span,
}),
}
}
pub fn extract_sm_strs(value: Value) -> Result<Vec<PlSmallStr>, ShellError> {
let span = value.span();
match (
<String as FromValue>::from_value(value.clone()),
<Vec<String> as FromValue>::from_value(value),
) {
(Ok(col), Err(_)) => Ok(vec![col.into()]),
(Err(_), Ok(cols)) => Ok(cols.iter().map(PlSmallStr::from).collect()),
_ => Err(ShellError::IncompatibleParametersSingle {
msg: "Expected a string or list of strings".into(),
span,
}),
}
}