xinrong-meng commented on code in PR #37560:
URL: https://github.com/apache/spark/pull/37560#discussion_r948586588
##########
python/pyspark/sql/tests/test_functions.py:
##########
@@ -959,6 +961,25 @@ def test_lit_day_time_interval(self):
actual = self.spark.range(1).select(lit(td)).first()[0]
self.assertEqual(actual, td)
+ def test_np_scalars(self):
+ from pyspark.sql.functions import array_contains, array_position
+
+ df = self.spark.createDataFrame([([1, 2, 3],), ([],)], ["data"])
+ for dtype in [np.int8, np.int16, np.int32, np.int64]:
+ self.assertEqual(df.select(lit(dtype(1))).dtypes, [("1", "int")])
+ res = df.select(array_contains(df.data,
dtype(1)).alias("b")).collect()
+ self.assertEqual([Row(b=True), Row(b=False)], res)
+ res = df.select(array_position(df.data,
dtype(1)).alias("c")).collect()
+ self.assertEqual([Row(c=1), Row(c=0)], res)
+
+ df = self.spark.createDataFrame([([1.0, 2.0, 3.0],), ([],)], ["data"])
+ for dtype in [np.float32, np.float64]:
+ self.assertEqual(df.select(lit(dtype(1))).dtypes, [("1.0",
"double")])
Review Comment:
Sounds good! Created https://issues.apache.org/jira/browse/SPARK-40131 as a
follow-up for that.
--
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]