Skip to content

Commit 7332969

Browse files
committed
Add tests for unsupported type.
1 parent 94d05f4 commit 7332969

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

python/pyspark/sql/tests.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,6 +3383,15 @@ def test_vectorized_udf_varargs(self):
33833383
res = df.select(f(col('id')))
33843384
self.assertEquals(df.collect(), res.collect())
33853385

3386+
def test_vectorized_udf_unsupported_types(self):
3387+
from pyspark.sql.functions import pandas_udf, col
3388+
schema = StructType([StructField("dt", DateType(), True)])
3389+
df = self.spark.createDataFrame([(datetime.date(1970, 1, 1),)], schema=schema)
3390+
f = pandas_udf(lambda x: x, DateType())
3391+
with QuietTest(self.sc):
3392+
with self.assertRaisesRegexp(Exception, 'Unsupported data type'):
3393+
df.select(f(col('dt'))).collect()
3394+
33863395

33873396
@unittest.skipIf(not _have_pandas or not _have_arrow, "Pandas or Arrow not installed")
33883397
class GroupbyApplyTests(ReusedPySparkTestCase):
@@ -3561,6 +3570,16 @@ def test_wrong_args(self):
35613570
with self.assertRaisesRegexp(ValueError, 'returnType'):
35623571
df.groupby('id').apply(pandas_grouped_udf(lambda x: x, DoubleType()))
35633572

3573+
def test_unsupported_types(self):
3574+
from pyspark.sql.functions import pandas_grouped_udf, col
3575+
schema = StructType(
3576+
[StructField("id", LongType(), True), StructField("dt", DateType(), True)])
3577+
df = self.spark.createDataFrame([(1, datetime.date(1970, 1, 1),)], schema=schema)
3578+
f = pandas_grouped_udf(lambda x: x, df.schema)
3579+
with QuietTest(self.sc):
3580+
with self.assertRaisesRegexp(Exception, 'Unsupported data type'):
3581+
df.groupby('id').apply(f).collect()
3582+
35643583

35653584
if __name__ == "__main__":
35663585
from pyspark.sql.tests import *

0 commit comments

Comments
 (0)