ueshin commented on code in PR #37560:
URL: https://github.com/apache/spark/pull/37560#discussion_r949690449
##########
python/pyspark/sql/tests/test_functions.py:
##########
@@ -959,9 +961,29 @@ def test_lit_day_time_interval(self):
actual = self.spark.range(1).select(lit(td)).first()[0]
self.assertEqual(actual, td)
+ @unittest.skipIf(not have_numpy, "NumPy not installed")
+ def test_np_scalar_input(self):
+ import numpy as np
+ 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)
Review Comment:
What if `np.int64` contains a big number over integer maximum?
##########
python/pyspark/sql/tests/test_functions.py:
##########
@@ -959,9 +961,29 @@ def test_lit_day_time_interval(self):
actual = self.spark.range(1).select(lit(td)).first()[0]
self.assertEqual(actual, td)
+ @unittest.skipIf(not have_numpy, "NumPy not installed")
+ def test_np_scalar_input(self):
+ import numpy as np
+ 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")])
Review Comment:
What was the data types when `spark.createDataFrame` with numpy values?
--
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]