From 8d46398e13de4569871cfc46e3e23924d3529da2 Mon Sep 17 00:00:00 2001 From: pyz4 <42039243+pyz4@users.noreply.github.com> Date: Sat, 7 Jun 2025 12:46:02 -0400 Subject: [PATCH] fix(polars): swap out pivot for pivot_stable to suppress warning message (#15913) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description The current implementation of `polars pivot` calls an unsupported version of pivot that throws a warning message in stdout (using println!) stating that "unstable pivot not yet unsupported, using stable pivot." This PR swaps out the call to `pivot` with a call to `pivot_stable`, which is being done in the underlying polars anyways. ```nushell # Current Implementation > [[a b c]; [1 x 10] [1 y 10] [2 x 11] [2 y 11]] | polars into-df | polars pivot -i [a] -o [b] -v [c] unstable pivot not yet supported, using stable pivot ╭───┬───┬────┬────╮ │ # │ a │ x │ y │ ├───┼───┼────┼────┤ │ 0 │ 1 │ 10 │ 10 │ │ 1 │ 2 │ 11 │ 11 │ # Proposed Implementation (no println! statement) > [[a b c]; [1 x 10] [1 y 10] [2 x 11] [2 y 11]] | polars into-df | polars pivot -i [a] -o [b] -v [c] ╭───┬───┬────┬────╮ │ # │ a │ x │ y │ ├───┼───┼────┼────┤ │ 0 │ 1 │ 10 │ 10 │ │ 1 │ 2 │ 11 │ 11 │ ╰───┴───┴────┴────╯ ``` # User-Facing Changes None # Tests + Formatting Current suite of tests were sufficient # After Submitting --- crates/nu_plugin_polars/src/dataframe/command/data/pivot.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/nu_plugin_polars/src/dataframe/command/data/pivot.rs b/crates/nu_plugin_polars/src/dataframe/command/data/pivot.rs index f2eb6b596d..7522eb2de2 100644 --- a/crates/nu_plugin_polars/src/dataframe/command/data/pivot.rs +++ b/crates/nu_plugin_polars/src/dataframe/command/data/pivot.rs @@ -5,7 +5,7 @@ use nu_protocol::{ }; use chrono::DateTime; -use polars_ops::pivot::{PivotAgg, pivot}; +use polars_ops::pivot::{PivotAgg, pivot_stable}; use crate::{ PolarsPlugin, @@ -237,7 +237,7 @@ fn command_eager( let polars_df = df.to_polars(); // todo add other args - let pivoted = pivot( + let pivoted = pivot_stable( &polars_df, &on_col_string, Some(&index_col_string),