mirror of
https://github.com/nushell/nushell.git
synced 2025-04-09 21:28:55 +02:00
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 arg-unique"
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Returns indexes for unique values"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build("dataframe arg-unique")
|
|
}
|
|
|
|
fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|
command(args)
|
|
}
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
vec![Example {
|
|
description: "Returns indexes for unique values",
|
|
example: "[1 2 2 3 3] | dataframe to-series | dataframe arg-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()
|
|
.arg_unique()
|
|
.map_err(|e| parse_polars_error::<&str>(&e, &tag.span, None))?;
|
|
|
|
Ok(OutputStream::one(NuSeries::series_to_value(
|
|
res.into_series(),
|
|
tag,
|
|
)))
|
|
}
|