Skip to content

Commit

Permalink
add tests to polars unique (#12683)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
maxim-uvarov committed Apr 27, 2024
1 parent 76d1d70 commit 884d531
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions crates/nu_plugin_polars/src/dataframe/series/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 884d531

Please sign in to comment.