viirya commented on a change in pull request #32332:
URL: https://github.com/apache/spark/pull/32332#discussion_r678905960



##########
File path: python/pyspark/sql/tests/test_dataframe.py
##########
@@ -759,6 +759,22 @@ def test_create_dataframe_from_pandas_with_dst(self):
                 os.environ['TZ'] = orig_env_tz
             time.tzset()
 
+    # SPARK-35211: inferred schema verification
+    @unittest.skipIf(not have_pandas, pandas_requirement_message)  # type: 
ignore
+    def test_create_dataframe_from_pandas_with_mismatched_udt(self):
+        from pyspark.testing.sqlutils import ExamplePoint
+        import pandas as pd
+        pdf = pd.DataFrame({'point': pd.Series([ExamplePoint(1, 1), 
ExamplePoint(2, 2)])})
+        # The underlying sqlType of ExamplePoint is ArrayType(DoubleType(), 
False)
+        # There is a data type mismatch between 1 and DoubleType, a TypeError 
is expected
+        with self.assertRaises(TypeError):
+            with self.sql_conf({"spark.sql.execution.arrow.pyspark.enabled": 
"false"}):
+                self.spark.createDataFrame(pdf)
+
+    def test_create_dataframe_with_mismatched_datatype(self):
+        with self.assertRaises(TypeError):
+            self.spark.createDataFrame([1, 2, 3], schema="a double")
+

Review comment:
       Could you call `createDataFrame`  with `verifySchema = False`?

##########
File path: python/pyspark/sql/tests/test_dataframe.py
##########
@@ -759,6 +759,22 @@ def test_create_dataframe_from_pandas_with_dst(self):
                 os.environ['TZ'] = orig_env_tz
             time.tzset()
 
+    # SPARK-35211: inferred schema verification
+    @unittest.skipIf(not have_pandas, pandas_requirement_message)  # type: 
ignore
+    def test_create_dataframe_from_pandas_with_mismatched_udt(self):
+        from pyspark.testing.sqlutils import ExamplePoint
+        import pandas as pd
+        pdf = pd.DataFrame({'point': pd.Series([ExamplePoint(1, 1), 
ExamplePoint(2, 2)])})
+        # The underlying sqlType of ExamplePoint is ArrayType(DoubleType(), 
False)
+        # There is a data type mismatch between 1 and DoubleType, a TypeError 
is expected
+        with self.assertRaises(TypeError):
+            with self.sql_conf({"spark.sql.execution.arrow.pyspark.enabled": 
"false"}):
+                self.spark.createDataFrame(pdf)
+
+    def test_create_dataframe_with_mismatched_datatype(self):
+        with self.assertRaises(TypeError):
+            self.spark.createDataFrame([1, 2, 3], schema="a double")
+

Review comment:
       Could you also add a call `createDataFrame`  with `verifySchema = False`?




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to