snowflakedb / snowflakedb/snowpark-python
SNOW-2043855: Window function 'rank' doesn't seem to work correcly in local testing mode
Open
Nobody has claimed this yet.
bug
local testing
status-triage_done
- Dominant language
- Python
- Stars
- 341
- Forks
- 155
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 27
Description
Please answer these questions before submitting your issue. Thanks!
-
What version of Python are you using?
3.9.20 -
What are the Snowpark Python and pandas versions in the environment?
pandas==2.2.3
snowflake-snowpark-python==1.30.0 -
What did you do?
from snowflake.snowpark import Session
from snowflake.snowpark.window import Window
import snowflake.snowpark.functions as func
session = Session.builder.config("local_testing", True).create()
df_to_test = session.create_dataframe(
[
("hello", 1),
("hello", 1),
("hello", 2),
("hello", 3),
],
["col1", "col2"],
)
window_spec_asc = Window.partition_by(func.col("col1")).order_by(func.col("col2").asc())
window_spec_desc = Window.partition_by(func.col("col1")).order_by(func.col("col2").desc())
df_ranked_asc = df_to_test.with_column("rank", func.rank().over(window_spec_asc))
df_ranked_desc = df_to_test.with_column("rank", func.rank().over(window_spec_desc))
df_ranked_asc.orderBy("rank").show()
df_ranked_desc.orderBy("rank").show()
- What did you expect to see?
I expected the following output:
----------------------------
|"COL1" |"COL2" |"RANK" |
----------------------------
|hello |1 |1 |
|hello |1 |1 |
|hello |2 |3 |
|hello |3 |4 |
----------------------------
----------------------------
|"COL1" |"COL2" |"RANK" |
----------------------------
|hello |3 |1 |
|hello |2 |2 |
|hello |1 |3 |
|hello |1 |3 |
----------------------------
But I actually get the following output:
----------------------------
|"COL1" |"COL2" |"RANK" |
----------------------------
|hello |1 |1 |
|hello |1 |1 |
|hello |2 |3 |
|hello |3 |4 |
----------------------------
----------------------------
|"COL1" |"COL2" |"RANK" |
----------------------------
|hello |1 |1 |
|hello |1 |1 |
|hello |2 |3 |
|hello |3 |4 |
----------------------------
So the ascending or descending order in the window specification doesn't seem to have the effect it should have.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.