use crate::prelude::*; use nu_engine::WholeStreamCommand; use nu_errors::ShellError; use nu_protocol::{ dataframe::{Column, NuDataFrame}, Signature, UntaggedValue, }; use polars::prelude::IntoSeries; pub struct DataFrame; impl WholeStreamCommand for DataFrame { fn name(&self) -> &str { "dataframe is-not-null" } fn usage(&self) -> &str { "[Series] Creates mask where value is not null" } fn signature(&self) -> Signature { Signature::build("dataframe is-not-null") } fn run(&self, args: CommandArgs) -> Result { command(args) } fn examples(&self) -> Vec { vec![Example { description: "Create mask where values are not null", example: r#"let s = ([5 6 0 8] | dataframe to-df); let res = ($s / $s); $res | dataframe is-not-null"#, result: Some(vec![NuDataFrame::try_from_columns( vec![Column::new( "is_not_null".to_string(), vec![ UntaggedValue::boolean(true).into(), UntaggedValue::boolean(true).into(), UntaggedValue::boolean(false).into(), UntaggedValue::boolean(true).into(), ], )], &Span::default(), ) .expect("simple df for test should not fail") .into_value(Tag::default())]), }] } } fn command(mut args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); let (df, df_tag) = NuDataFrame::try_from_stream(&mut args.input, &tag.span)?; let res = df.as_series(&df_tag.span)?.is_not_null(); let df = NuDataFrame::try_from_series(vec![res.into_series()], &tag.span)?; Ok(OutputStream::one(df.into_value(df_tag))) } #[cfg(test)] mod tests { use super::DataFrame; use super::ShellError; #[test] fn examples_work_as_expected() -> Result<(), ShellError> { use crate::examples::test_dataframe as test_examples; test_examples(DataFrame {}) } }