File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
src/snowflake/snowpark/mock Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -707,6 +707,18 @@ def mock_abs(expr):
707707 return abs (expr )
708708
709709
710+ @patch ("nullifzero" )
711+ def mock_nullifzero (expr : ColumnEmulator ) -> ColumnEmulator :
712+ def convert_zero_to_null (value ):
713+ if value == 0 or value == 0.0 :
714+ return None
715+ return value
716+
717+ result = expr .apply (convert_zero_to_null )
718+ result .sf_type = ColumnType (expr .sf_type .datatype , nullable = True )
719+ return result
720+
721+
710722@patch ("to_decimal" )
711723def mock_to_decimal (
712724 e : ColumnEmulator ,
Original file line number Diff line number Diff line change @@ -161,6 +161,31 @@ def test_abs(session):
161161 assert origin_df .select (abs (col ("m" ))).collect () == [Row (1 ), Row (1 ), Row (2 )]
162162
163163
164+ def test_nullifzero (session ):
165+ """Test nullifzero function converts 0 to NULL while preserving other values."""
166+ from snowflake .snowpark .functions import nullifzero
167+
168+ df = session .create_dataframe (
169+ [
170+ [0 ],
171+ [1 ],
172+ [0.0 ],
173+ [100 ],
174+ [- 5 ],
175+ ],
176+ schema = ["value" ],
177+ )
178+ result = df .select (nullifzero (col ("value" )).alias ("result" )).collect ()
179+
180+ assert result == [
181+ Row (RESULT = None ),
182+ Row (RESULT = 1 ),
183+ Row (RESULT = None ),
184+ Row (RESULT = 100 ),
185+ Row (RESULT = - 5 ),
186+ ]
187+
188+
164189def test_asc_and_desc (session ):
165190 origin_df : DataFrame = session .create_dataframe (
166191 [
You can’t perform that action at this time.
0 commit comments