Github user HyukjinKwon commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17227#discussion_r123875195
  
    --- Diff: python/pyspark/sql/types.py ---
    @@ -1249,7 +1249,7 @@ def _infer_schema_type(obj, dataType):
     }
     
     
    -def _verify_type(obj, dataType, nullable=True):
    +def _verify_type(obj, dataType, nullable=True, name="obj"):
    --- End diff --
    
    Let's fix this case.
    
    ```python
    >>> from pyspark.sql.types import *
    >>> spark.createDataFrame(["a"], StringType()).printSchema()
    ```
    
    ```
    root
     |-- value: string (nullable = true)
    ```
    ```python
    >>> from pyspark.sql.types import *
    >>> spark.createDataFrame(["a"], IntegerType()).printSchema()
    ```
    ```
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File ".../spark/python/pyspark/sql/session.py", line 526, in 
createDataFrame
        rdd, schema = self._createFromLocal(map(prepare, data), schema)
      File ".../spark/python/pyspark/sql/session.py", line 387, in 
_createFromLocal
        data = list(data)
      File ".../spark/python/pyspark/sql/session.py", line 516, in prepare
        verify_func(obj, dataType)
      File ".../spark/python/pyspark/sql/types.py", line 1326, in _verify_type
        % (name, dataType, obj, type(obj)))
    TypeError: obj: IntegerType can not accept object 'a' in type <type 'str'>
    ```
    
    It sounds "obj" should be "value". It looks we should specify the name 
around 
https://github.com/dgingrich/spark/blob/topic-spark-19507-verify-types/python/pyspark/sql/session.py#L516.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to