From 884d5312bb18498a8bfb363be07837b2d1bdf6aa Mon Sep 17 00:00:00 2001 From: Maxim Uvarov Date: Sun, 28 Apr 2024 01:04:54 +0800 Subject: [PATCH] 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. --- .../src/dataframe/series/unique.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/crates/nu_plugin_polars/src/dataframe/series/unique.rs b/crates/nu_plugin_polars/src/dataframe/series/unique.rs index dfc4e76b25..8feec32c11 100644 --- a/crates/nu_plugin_polars/src/dataframe/series/unique.rs +++ b/crates/nu_plugin_polars/src/dataframe/series/unique.rs @@ -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",