Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/snowflake/snowpark/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2153,7 +2153,8 @@ def sort(
-------------
<BLANKLINE>

>>> df.sort(ascending=False).show()
>>> # Sort by all columns (ORDER BY ALL) - no columns specified
>>> df.sort([], ascending=False).show()
-------------
|"A" |"B" |
-------------
Expand Down Expand Up @@ -2182,7 +2183,10 @@ def sort(
The aliases ``order_by()`` and ``orderBy()`` have the same behavior.
"""

is_order_by_all = not cols
# This code performs additional type checks, run first.
exprs = self._convert_cols_to_exprs("sort()", *cols)
is_order_by_all = not cols or not exprs

if (
is_order_by_all
and ascending is not None
Expand Down Expand Up @@ -2230,10 +2234,6 @@ def sort(
order = Ascending() if bool(asc_value) else Descending()
sort_exprs = [SortByAllOrder(order)]
else:
exprs = self._convert_cols_to_exprs("sort()", *cols)
if not exprs:
raise ValueError("sort() needs at least one sort expression.")

orders = []
if ascending is not None:
if isinstance(ascending, (list, tuple)):
Expand Down
5 changes: 0 additions & 5 deletions tests/integ/scala/test_dataframe_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,11 +1219,6 @@ def test_sort(session):
for i in range(len(sorted_rows) - 1)
]

# Negative test: sort() needs at least one sort expression
with pytest.raises(ValueError) as ex_info:
df.sort([])
assert "sort() needs at least one sort expression" in ex_info.value.args[0]


def test_select(session):
df = session.create_dataframe([(1, "a", 10), (2, "b", 20), (3, "c", 30)]).to_df(
Expand Down
4 changes: 4 additions & 0 deletions tests/integ/test_simplifier_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,10 @@ def test_sort_by_all_sql_simplifier(session, use_simplified_query_generation):
df2 = df.select("a", "b", "c").sort(ascending=False)
assert "ORDER BY" and "ALL" in df2.queries["queries"][0].upper()
Utils.check_answer(df2, [Row(3, "c", 30), Row(2, "b", 20), Row(1, "a", 10)])

df3 = df.select("a", "b").orderBy([], ascending=True)
assert "ORDER BY" and "ALL" in df3.queries["queries"][0].upper()
Utils.check_answer(df3, df1)
finally:
session.conf.set("use_simplified_query_generation", original)

Expand Down