You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "itholic (via GitHub)" <gi...@apache.org> on 2024/01/24 03:19:23 UTC

[PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

itholic opened a new pull request, #44859:
URL: https://github.com/apache/spark/pull/44859

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
     8. If you want to add or modify an error type or message, please read the guideline first in
        'core/src/main/resources/error/README.md'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   This PR proposes to improve error message when `createDataFrame` fails nullability check
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   The current error message is not proper and also not actionable.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   
   No API change, but the user-facing error message is improved
   
   **Before**
   ```python
   >>> from pyspark.sql.types import StructType, StructField, StringType, IntegerType
   >>> schema = StructType([
   ...     StructField("name", StringType(), nullable=True),
   ...     StructField("age", IntegerType(), nullable=False)
   ... ])
   >>> df = spark.createDataFrame([(["asd", None])], schema)
   pyspark.errors.exceptions.base.PySparkValueError: [CANNOT_BE_NONE] Argument `obj` cannot be None.
   ```
   
   **After**
   ```python
   >>> from pyspark.sql.types import StructType, StructField, StringType, IntegerType
   >>> schema = StructType([
   ...     StructField("name", StringType(), nullable=True),
   ...     StructField("age", IntegerType(), nullable=False)
   ... ])
   >>> df = spark.createDataFrame([(["asd", None])], schema)
   pyspark.errors.exceptions.base.PySparkValueError: [NULLABILITY_CHECK_FAILED] The nullability check is failed. Make sure the parameter does not contain None.
   ```
   
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   Manually test
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   No.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464286547


##########
python/pyspark/errors/error_classes.py:
##########
@@ -742,6 +742,11 @@
       "Only allows <arg_name> to be a path without scheme, and Spark Driver should use the default scheme to determine the destination file system."
     ]
   },
+  "NULLABILITY_CHECK_FAILED": {

Review Comment:
   We have a plan to refine the error classes, but not sure which way is the best:
   
   1. We can create one representing main error class and make these similar error classes into sub-error classes under it.
   2. We can consolidate them all and make the type name as a message parameter.



##########
python/pyspark/errors/error_classes.py:
##########
@@ -742,6 +742,11 @@
       "Only allows <arg_name> to be a path without scheme, and Spark Driver should use the default scheme to determine the destination file system."
     ]
   },
+  "NULLABILITY_CHECK_FAILED": {

Review Comment:
   > do we plan to consolidate those NOT_STR/NOT_STRUCT error classes?
   
   We have a plan to refine the error classes, but not sure which way is the best:
   
   1. We can create one representing main error class and make these similar error classes into sub-error classes under it.
   2. We can consolidate them all and make the type name as a message parameter.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464259286


##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,8 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="NULLABILITY_CHECK_FAILED",
+                    message_parameters={},

Review Comment:
   So, maybe we should like
   
   **Before (current regression)**
   ```python
               raise PySparkTypeError(
                   error_class="CANNOT_ACCEPT_OBJECT_IN_TYPE",
                   message_parameters={
                       "data_type": str(dataType),
                       "obj_name": str(obj),
                       "obj_type": type(obj).__name__,
                   },
   ```
   
   **After**
   ```python
               raise PySparkTypeError(
                   message=new_msg("%s can not accept object %r in type %s" % (dataType, obj, type(obj))),
               )
   ```
   ?



##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,8 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="NULLABILITY_CHECK_FAILED",
+                    message_parameters={},

Review Comment:
   So, maybe we should fix like
   
   **Before (current regression)**
   ```python
               raise PySparkTypeError(
                   error_class="CANNOT_ACCEPT_OBJECT_IN_TYPE",
                   message_parameters={
                       "data_type": str(dataType),
                       "obj_name": str(obj),
                       "obj_type": type(obj).__name__,
                   },
   ```
   
   **After**
   ```python
               raise PySparkTypeError(
                   message=new_msg("%s can not accept object %r in type %s" % (dataType, obj, type(obj))),
               )
   ```
   ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464290122


##########
python/pyspark/errors/error_classes.py:
##########
@@ -742,6 +742,11 @@
       "Only allows <arg_name> to be a path without scheme, and Spark Driver should use the default scheme to determine the destination file system."
     ]
   },
+  "NULLABILITY_CHECK_FAILED": {

Review Comment:
   Will create a ticket for it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464263105


##########
python/pyspark/errors/error_classes.py:
##########
@@ -742,6 +742,11 @@
       "Only allows <arg_name> to be a path without scheme, and Spark Driver should use the default scheme to determine the destination file system."
     ]
   },
+  "NULLABILITY_CHECK_FAILED": {

Review Comment:
   +1, BTW, do we plan to consolidate those `NOT_STR`/`NOT_STRUCT` error classes?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464361491


##########
python/pyspark/sql/types.py:
##########
@@ -2214,12 +2211,9 @@ def verify_acceptable_types(obj: Any) -> None:
         # subclass of them can not be fromInternal in JVM
         if type(obj) not in _acceptable_types[_type]:
             raise PySparkTypeError(
-                error_class="CANNOT_ACCEPT_OBJECT_IN_TYPE",
-                message_parameters={
-                    "data_type": str(dataType),
-                    "obj_name": str(obj),
-                    "obj_type": type(obj).__name__,
-                },

Review Comment:
   Can we have the error class properly with fixing `new_msg` togehter? `new_msg` just appends `name` in front.  Also `object of ByteType out of range, got`, `object of ShortType out of range, got` has common messages too?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464253152


##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,8 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="NULLABILITY_CHECK_FAILED",
+                    message_parameters={},

Review Comment:
   We should call `new_msg` to make the error message properly shown.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464259286


##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,8 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="NULLABILITY_CHECK_FAILED",
+                    message_parameters={},

Review Comment:
   So, maybe we should like
   
   Before
   ```python
               raise PySparkTypeError(
                   error_class="CANNOT_ACCEPT_OBJECT_IN_TYPE",
                   message_parameters={
                       "data_type": str(dataType),
                       "obj_name": str(obj),
                       "obj_type": type(obj).__name__,
                   },
   ```
   
   After
   ```python
               raise PySparkTypeError(
                   message=new_msg("%s can not accept object %r in type %s" % (dataType, obj, type(obj))),
               )
   ```
   ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464287109


##########
python/pyspark/errors/error_classes.py:
##########
@@ -742,6 +742,11 @@
       "Only allows <arg_name> to be a path without scheme, and Spark Driver should use the default scheme to determine the destination file system."
     ]
   },
+  "NULLABILITY_CHECK_FAILED": {

Review Comment:
   I personally prefer option 2.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #44859:
URL: https://github.com/apache/spark/pull/44859#issuecomment-1953372881

   Merged to master.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464258517


##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,8 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="NULLABILITY_CHECK_FAILED",
+                    message_parameters={},

Review Comment:
   Oh.. it sounds like `types.py` has its own error message generation logic - called `new_msg` - and some error messages are should be generated use it instead of using error class defined in `error_classes.py` ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464318444


##########
python/pyspark/sql/types.py:
##########
@@ -2214,12 +2211,9 @@ def verify_acceptable_types(obj: Any) -> None:
         # subclass of them can not be fromInternal in JVM
         if type(obj) not in _acceptable_types[_type]:
             raise PySparkTypeError(
-                error_class="CANNOT_ACCEPT_OBJECT_IN_TYPE",
-                message_parameters={
-                    "data_type": str(dataType),
-                    "obj_name": str(obj),
-                    "obj_type": type(obj).__name__,
-                },

Review Comment:
   Shall we have an error class?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464286547


##########
python/pyspark/errors/error_classes.py:
##########
@@ -742,6 +742,11 @@
       "Only allows <arg_name> to be a path without scheme, and Spark Driver should use the default scheme to determine the destination file system."
     ]
   },
+  "NULLABILITY_CHECK_FAILED": {

Review Comment:
   > do we plan to consolidate those NOT_STR/NOT_STRUCT error classes?
   
   We have a plan to refine the error classes, but not sure which way is better among 2 methods below:
   
   1. We can create one representing main error class and make these similar error classes into sub-error classes under it.
   2. We can consolidate them all and make the type name as a message parameter.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464344002


##########
python/pyspark/sql/types.py:
##########
@@ -2214,12 +2211,9 @@ def verify_acceptable_types(obj: Any) -> None:
         # subclass of them can not be fromInternal in JVM
         if type(obj) not in _acceptable_types[_type]:
             raise PySparkTypeError(
-                error_class="CANNOT_ACCEPT_OBJECT_IN_TYPE",
-                message_parameters={
-                    "data_type": str(dataType),
-                    "obj_name": str(obj),
-                    "obj_type": type(obj).__name__,
-                },

Review Comment:
   Yes we can, but the error class would contain less meaningful contents, for example as below:
   
   ```python
     "CANNOT_ACCEPT_OBJECT_IN_TYPE": {
       "message": [
         "<message>"
       ]
     },
   ```
   
   because we generate whole error message here.
   
   Shall we add an error class anyway?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1495156397


##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,10 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="FIELD_NOT_NULLABLE",
+                    message_parameters={
+                        "field_name": name if name is not None else "",

Review Comment:
   Separated into two error class `FIELD_NOT_NULLABLE` and `FIELD_NOT_NULLABLE_WITN_NAME`. Please let me know if any other suggestions!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464286547


##########
python/pyspark/errors/error_classes.py:
##########
@@ -742,6 +742,11 @@
       "Only allows <arg_name> to be a path without scheme, and Spark Driver should use the default scheme to determine the destination file system."
     ]
   },
+  "NULLABILITY_CHECK_FAILED": {

Review Comment:
   > do we plan to consolidate those NOT_STR/NOT_STRUCT error classes?
   
   We have a plan to refine the error classes, but not sure which way is better:
   
   1. We can create one representing main error class and make these similar error classes into sub-error classes under it.
   2. We can consolidate them all and make the type name as a message parameter.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464253044


##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,8 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="NULLABILITY_CHECK_FAILED",
+                    message_parameters={},

Review Comment:
   @itholic actually I think we have a regression here. https://github.com/apache/spark/commit/04816474bfcc05c7d90f7b7e8d35184d95c78cbd#diff-bb02965370d515ec7add7967bc949c18c88ffc7346cceaebefb84907dfdce903L1933



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464252162


##########
python/pyspark/errors/error_classes.py:
##########
@@ -742,6 +742,11 @@
       "Only allows <arg_name> to be a path without scheme, and Spark Driver should use the default scheme to determine the destination file system."
     ]
   },
+  "NULLABILITY_CHECK_FAILED": {

Review Comment:
   Can we name it like `NOT_NONE` to be consistent with others like`NOT_STR`, `NOT_STRUCT`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464503772


##########
python/pyspark/sql/types.py:
##########
@@ -2214,12 +2211,9 @@ def verify_acceptable_types(obj: Any) -> None:
         # subclass of them can not be fromInternal in JVM
         if type(obj) not in _acceptable_types[_type]:
             raise PySparkTypeError(
-                error_class="CANNOT_ACCEPT_OBJECT_IN_TYPE",
-                message_parameters={
-                    "data_type": str(dataType),
-                    "obj_name": str(obj),
-                    "obj_type": type(obj).__name__,
-                },

Review Comment:
   Sure, will push another commit after addressing comments.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464263105


##########
python/pyspark/errors/error_classes.py:
##########
@@ -742,6 +742,11 @@
       "Only allows <arg_name> to be a path without scheme, and Spark Driver should use the default scheme to determine the destination file system."
     ]
   },
+  "NULLABILITY_CHECK_FAILED": {

Review Comment:
   +1, BTW, do we plan to consolidate those `NOT_STR`/`NOT_STRUCT` error classes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464268453


##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,8 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="NULLABILITY_CHECK_FAILED",
+                    message_parameters={},

Review Comment:
   Oh,, sorry I didn't realize that. Let me fix them within this PR and will update the PR title & description accordingly.
   
   Thanks for the context!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1488780632


##########
python/pyspark/sql/types.py:
##########
@@ -2214,12 +2211,9 @@ def verify_acceptable_types(obj: Any) -> None:
         # subclass of them can not be fromInternal in JVM
         if type(obj) not in _acceptable_types[_type]:
             raise PySparkTypeError(
-                error_class="CANNOT_ACCEPT_OBJECT_IN_TYPE",
-                message_parameters={
-                    "data_type": str(dataType),
-                    "obj_name": str(obj),
-                    "obj_type": type(obj).__name__,
-                },

Review Comment:
   CI finally turns to green



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1490402927


##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,10 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="FIELD_NOT_NULLABLE",
+                    message_parameters={
+                        "field_name": name if name is not None else "",

Review Comment:
   Seems like the error message would look weird if this is an empty string.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #44859: [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg`
URL: https://github.com/apache/spark/pull/44859


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464263776


##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,8 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="NULLABILITY_CHECK_FAILED",
+                    message_parameters={},

Review Comment:
   Yeah new_msg reclusively track the column name



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on PR #44859:
URL: https://github.com/apache/spark/pull/44859#issuecomment-1907351039

   Thanks @HyukjinKwon for reviewing. Just restored regressions from past few PRs, and updated the PR title & description accordingly.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464255714


##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,8 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="NULLABILITY_CHECK_FAILED",
+                    message_parameters={},

Review Comment:
   See https://github.com/apache/spark/pull/18521. We should have the same error messages as https://gist.github.com/HyukjinKwon/7a494e4557fe32a652ce1236e504a395



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Improve error message when `createDataFrame` fails nullability check [spark]

Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464254349


##########
python/pyspark/sql/types.py:
##########
@@ -2197,8 +2197,8 @@ def verify_nullability(obj: Any) -> bool:
                 return True
             else:
                 raise PySparkValueError(
-                    error_class="CANNOT_BE_NONE",
-                    message_parameters={"arg_name": "obj"},
+                    error_class="NULLABILITY_CHECK_FAILED",
+                    message_parameters={},

Review Comment:
   https://github.com/apache/spark/pull/40975 too.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-46820][PYTHON] Fix error message regression by restoring `new_msg` [spark]

Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #44859:
URL: https://github.com/apache/spark/pull/44859#discussion_r1464289999


##########
python/pyspark/errors/error_classes.py:
##########
@@ -742,6 +742,11 @@
       "Only allows <arg_name> to be a path without scheme, and Spark Driver should use the default scheme to determine the destination file system."
     ]
   },
+  "NULLABILITY_CHECK_FAILED": {

Review Comment:
   Yeah although I have no strong opinion, but I also bit more prefer 2.
   
   The only thing I've been concerning is that it may harm readability in some places, but I believe it would not that much.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org