forked from extern/nushell
50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
use crate::{commands::dataframe::utils::parse_polars_error, prelude::*};
|
|
use nu_engine::WholeStreamCommand;
|
|
use nu_errors::ShellError;
|
|
use nu_protocol::{dataframe::NuSeries, Signature};
|
|
use polars::prelude::IntoSeries;
|
|
|
|
pub struct DataFrame;
|
|
|
|
impl WholeStreamCommand for DataFrame {
|
|
fn name(&self) -> &str {
|
|
"dataframe is-unique"
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Creates mask indicating unique values"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("dataframe is-unique")
|
|
}
|
|
|
|
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
command(args)
|
|
}
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
vec![Example {
|
|
description: "Create mask indicating unique values",
|
|
example: "[5 6 6 6 8 8 8] | dataframe to-series | dataframe is-unique",
|
|
result: None,
|
|
}]
|
|
}
|
|
}
|
|
|
|
fn command(mut args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
let tag = args.call_info.name_tag.clone();
|
|
|
|
let series = NuSeries::try_from_stream(&mut args.input, &tag.span)?;
|
|
|
|
let res = series
|
|
.as_ref()
|
|
.is_unique()
|
|
.map_err(|e| parse_polars_error::<&str>(&e, &tag.span, None))?;
|
|
|
|
Ok(OutputStream::one(NuSeries::series_to_value(
|
|
res.into_series(),
|
|
tag,
|
|
)))
|
|
}
|