add tests to polars unique (#12683)

# Description

I would like to help with `polars` plugin development and add tests to
all the `polars` command's existing params.

Since I have never written any lines of Rust, even though the task of
creating tests is relatively simple, I would like to ask for feedback to
ensure I did everything correctly here.
This commit is contained in:
Maxim Uvarov 2024-04-28 01:04:54 +08:00 committed by GitHub
parent 76d1d70e83
commit 884d5312bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -66,6 +66,59 @@ impl PluginCommand for Unique {
.into_value(Span::test_data()),
),
},
Example {
description: "Returns unique values in a subset of lazyframe columns",
example: "[[a b c]; [1 2 1] [2 2 2] [3 2 1]] | polars into-lazy | polars unique --subset [b c] | polars collect",
result: Some(
NuDataFrame::try_from_columns(
vec![
Column::new(
"a".to_string(),
vec![Value::test_int(1), Value::test_int(2)]
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(2)]
),
Column::new(
"c".to_string(),
vec![Value::test_int(1), Value::test_int(2)]
)
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
Example {
description: "Returns unique values in a subset of lazyframe columns",
example: r#"[[a b c]; [1 2 1] [2 2 2] [3 2 1]]
| polars into-lazy
| polars unique --subset [b c] --last
| polars collect"#,
result: Some(
NuDataFrame::try_from_columns(
vec![
Column::new(
"a".to_string(),
vec![Value::test_int(2), Value::test_int(3)]
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(2)]
),
Column::new(
"c".to_string(),
vec![Value::test_int(2), Value::test_int(1)]
)
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
Example {
description: "Creates a is unique expression from a column",
example: "col a | unique",