From 69a05147cfa441f0b6f7f9be20f6a4c1dc4e8961 Mon Sep 17 00:00:00 2001 From: Jamison Rose Date: Tue, 19 Dec 2023 07:26:56 -0800 Subject: [PATCH] SNOW-990324: Fix inconsistency when calling na.fill (#1182) --- CHANGELOG.md | 2 ++ src/snowflake/snowpark/dataframe_na_functions.py | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17eaff2c5ff..29548a437d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## 1.12.0 (TBD) ### Bug Fixes + +- Fixed a bug in `DataFrame.na.fill` that caused Boolean values to erroneously override integer values. - Fixed sql simplifier for filter with window function columns in select. ## 1.11.1 (2023-12-07) diff --git a/src/snowflake/snowpark/dataframe_na_functions.py b/src/snowflake/snowpark/dataframe_na_functions.py index 387a2e722d5..aecc5070fba 100644 --- a/src/snowflake/snowpark/dataframe_na_functions.py +++ b/src/snowflake/snowpark/dataframe_na_functions.py @@ -48,6 +48,8 @@ def _is_value_type_matching_for_na_function( value is None or ( isinstance(value, int) + # bool is a subclass of int, but we don't want to consider it numeric + and not isinstance(value, bool) and isinstance(datatype, (IntegerType, LongType, FloatType, DoubleType)) ) or (isinstance(value, float) and isinstance(datatype, (FloatType, DoubleType))) @@ -285,6 +287,17 @@ def fill( |3.14 |15 | -------------- + >>> df2 = session.create_dataframe([[1.0, True], [2.0, False], [3.0, False], [None, None]]).to_df("a", "b") + >>> df2.na.fill(True).show() + ---------------- + |"A" |"B" | + ---------------- + |1.0 |True | + |2.0 |False | + |3.0 |False | + |NULL |True | + ---------------- + Note: If the type of a given value in ``value`` doesn't match the