From b6eda33438fe4f4b30a5ae9b2d6d3b6a466c1296 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Wed, 6 Nov 2024 17:58:22 -0600 Subject: [PATCH] allow != for polars (#14263) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description This PR fixes a problem where not equal in polars wasn't working with strings. ## Before ```nushell let a = ls | polars into-df $a.type != "dir" Error: nu::shell::type_mismatch × Type mismatch during operation. ╭─[entry #16:1:1] 1 │ $a.type != "dir" · ─┬ ─┬ ──┬── · │ │ ╰── string · │ ╰── type mismatch for operator · ╰── NuDataFrame ╰──── ``` ## After ```nushell let a = ls | polars into-df $a.type != "dir" ╭──#──┬─type──╮ │ 0 │ false │ │ 1 │ false │ │ 2 │ false │ ... ``` /cc @ayax79 to make sure I did this right. # User-Facing Changes # Tests + Formatting # After Submitting --- .../src/dataframe/values/nu_dataframe/between_values.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/nu_plugin_polars/src/dataframe/values/nu_dataframe/between_values.rs b/crates/nu_plugin_polars/src/dataframe/values/nu_dataframe/between_values.rs index 382ae12de2..7d34d6d128 100644 --- a/crates/nu_plugin_polars/src/dataframe/values/nu_dataframe/between_values.rs +++ b/crates/nu_plugin_polars/src/dataframe/values/nu_dataframe/between_values.rs @@ -334,6 +334,10 @@ pub(super) fn compute_series_single_value( Value::Float { val, .. } => { compare_series_float(&lhs, *val, ChunkedArray::not_equal, lhs_span) } + Value::String { val, .. } => { + let equal_pattern = format!("^{}$", fancy_regex::escape(val)); + contains_series_pat(&lhs, &equal_pattern, lhs_span) + } Value::Date { val, .. } => compare_series_i64( &lhs, val.timestamp_millis(),