This is an automated email from the ASF dual-hosted git repository.

gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new d3f12df6e09e [SPARK-47437][PYTHON][CONNECT] Correct the error class 
for `DataFrame.sort*`
d3f12df6e09e is described below

commit d3f12df6e09ee47dbd7c9e08c9962430a2601941
Author: Ruifeng Zheng <ruife...@apache.org>
AuthorDate: Mon Mar 18 20:24:43 2024 +0900

    [SPARK-47437][PYTHON][CONNECT] Correct the error class for `DataFrame.sort*`
    
    ### What changes were proposed in this pull request?
    Correct the error class for `DataFrame.sort*`
    
    ### Why are the changes needed?
    `DataFrame.sort*` support negative indices, which means `sort by desc`
    
    ### Does this PR introduce _any_ user-facing change?
    yes
    
    ### How was this patch tested?
    ci
    
    ### Was this patch authored or co-authored using generative AI tooling?
    no
    
    Closes #45559 from zhengruifeng/correct_index_error.
    
    Authored-by: Ruifeng Zheng <ruife...@apache.org>
    Signed-off-by: Hyukjin Kwon <gurwls...@apache.org>
---
 python/pyspark/errors/error_classes.py  | 5 +++++
 python/pyspark/sql/connect/dataframe.py | 3 ++-
 python/pyspark/sql/dataframe.py         | 4 ++--
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/python/pyspark/errors/error_classes.py 
b/python/pyspark/errors/error_classes.py
index 1e21ad3543e9..6b7f19b44918 100644
--- a/python/pyspark/errors/error_classes.py
+++ b/python/pyspark/errors/error_classes.py
@@ -1162,6 +1162,11 @@ ERROR_CLASSES_JSON = '''
     "message": [
       "Function `<func_name>` should take at least <num_cols> columns."
     ]
+  },
+  "ZERO_INDEX": {
+    "message": [
+      "Index must be non-zero."
+    ]
   }
 }
 '''
diff --git a/python/pyspark/sql/connect/dataframe.py 
b/python/pyspark/sql/connect/dataframe.py
index bbb1be4c4724..f300774b6e57 100644
--- a/python/pyspark/sql/connect/dataframe.py
+++ b/python/pyspark/sql/connect/dataframe.py
@@ -701,7 +701,8 @@ class DataFrame:
                     _c = self[-c - 1].desc()
                 else:
                     raise PySparkIndexError(
-                        error_class="INDEX_NOT_POSITIVE", 
message_parameters={"index": str(c)}
+                        error_class="ZERO_INDEX",
+                        message_parameters={},
                     )
             else:
                 _c = c  # type: ignore[assignment]
diff --git a/python/pyspark/sql/dataframe.py b/python/pyspark/sql/dataframe.py
index 5c5c263b8156..d04c35dac5e9 100644
--- a/python/pyspark/sql/dataframe.py
+++ b/python/pyspark/sql/dataframe.py
@@ -3331,7 +3331,6 @@ class DataFrame(PandasMapOpsMixin, PandasConversionMixin):
         jcols = []
         for c in cols:
             if isinstance(c, int) and not isinstance(c, bool):
-                # TODO: should introduce dedicated error class
                 # ordinal is 1-based
                 if c > 0:
                     _c = self[c - 1]
@@ -3340,7 +3339,8 @@ class DataFrame(PandasMapOpsMixin, PandasConversionMixin):
                     _c = self[-c - 1].desc()
                 else:
                     raise PySparkIndexError(
-                        error_class="INDEX_NOT_POSITIVE", 
message_parameters={"index": str(c)}
+                        error_class="ZERO_INDEX",
+                        message_parameters={},
                     )
             else:
                 _c = c  # type: ignore[assignment]


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to