From 24a7ae320dea37efdd52d055c5f4732789fc2e1b Mon Sep 17 00:00:00 2001 From: Andong Zhan Date: Wed, 7 Feb 2024 15:02:34 -0800 Subject: [PATCH] =?UTF-8?q?SNOW-1016748=20Fixed=20a=20bug=20that=20Session?= =?UTF-8?q?.range=20returns=20empty=20result=20when=E2=80=A6=20(#1240)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../snowpark/_internal/analyzer/analyzer_utils.py | 2 +- tests/integ/scala/test_dataframe_range_suite.py | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61e0819491f..839ee75c7b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Fixed a bug in `DataFrame.to_pandas` that caused an error when evaluating on a dataframe with an IntergerType column with null values. - Fixed a bug in `DataFrame.to_local_iterator` where the iterator could yield wrong results if another query is executed before the iterator finishes due to wrong isolation level. For details, please see #945. - Fixed a bug that truncated table names in error messages while running a plan with local testing enabled. +- Fixed a bug that `Session.range` returns empty result when the range is large. ## 1.12.0 (2024-01-30) diff --git a/src/snowflake/snowpark/_internal/analyzer/analyzer_utils.py b/src/snowflake/snowpark/_internal/analyzer/analyzer_utils.py index 2b7a11f4d02..8ef0e7e2103 100644 --- a/src/snowflake/snowpark/_internal/analyzer/analyzer_utils.py +++ b/src/snowflake/snowpark/_internal/analyzer/analyzer_utils.py @@ -448,7 +448,7 @@ def sort_statement(order: List[str], child: str) -> str: def range_statement(start: int, end: int, step: int, column_name: str) -> str: range = end - start - if range * step < 0: + if (range > 0 > step) or (range < 0 < step): count = 0 else: count = math.ceil(range / step) diff --git a/tests/integ/scala/test_dataframe_range_suite.py b/tests/integ/scala/test_dataframe_range_suite.py index bc45bc7aaf4..63341da8ba7 100644 --- a/tests/integ/scala/test_dataframe_range_suite.py +++ b/tests/integ/scala/test_dataframe_range_suite.py @@ -10,6 +10,7 @@ from snowflake.snowpark import Row from snowflake.snowpark.functions import col, count, sum as sum_ +from tests.integ.test_packaging import is_pandas_and_numpy_available @pytest.mark.localtest @@ -108,3 +109,13 @@ def test_range_with_max_and_min(session): end = MIN_VALUE + 2 assert session.range(start, end, 1).collect() == [] assert session.range(start, start, 1).collect() == [] + + +@pytest.mark.skipif(not is_pandas_and_numpy_available, reason="requires numpy") +@pytest.mark.localtest +def test_range_with_large_range_and_step(session): + import numpy as np + + ints = np.array([691200000000000], dtype="int64") + # Use a numpy int64 range with a python int step + assert session.range(0, ints[0], 86400000000000).collect() != []