xinrong-meng commented on code in PR #37560:
URL: https://github.com/apache/spark/pull/37560#discussion_r952882996
##########
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:
The data mapping between NumPy dtype and PySpark dtypes when
`spark.createDataFrame` looks as below:
```
NumPy dtype: ["int8", "int16", "int32", "int64", "float32", "float64"]
PySpark dtypes: ["tinyint", "smallint", "int", "bigint", "float", "double"]
```
Unfortunately, we lost the precision here in Py4J. I may file a followup PR
to at least adjust that for `lit` function.
--
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]