xinrong-meng commented on code in PR #37635:
URL: https://github.com/apache/spark/pull/37635#discussion_r953211654
##########
python/pyspark/sql/tests/test_functions.py:
##########
@@ -1003,6 +1003,30 @@ def test_np_scalar_input(self):
res = df.select(array_position(df.data,
dtype(1)).alias("c")).collect()
self.assertEqual([Row(c=1), Row(c=0)], res)
+ @unittest.skipIf(not have_numpy, "NumPy not installed")
+ def test_ndarray_input(self):
+ import numpy as np
+
+ int_arrs = [np.array([1, 2]).astype(t) for t in ["int8", "int16",
"int32", "int64"]]
+ for arr in int_arrs:
+ self.assertEqual(
+ [Row(b=[1, 2])],
self.spark.range(1).select(lit(arr).alias("b")).collect()
+ )
+
+ float_arrs = [np.array([0.1, 0.2]).astype(t) for t in ["float32",
"float64"]]
+
+ self.assertEqual(
Review Comment:
Cannot compare Row equality
```
self.assertEqual(Row(b=[0.10000000149011612, 0.20000000298023224]),
self.spark.range(1).select(lit(float_arrs[0]).alias("b")).collect())
```
due to
```
AssertionError: Row(b=[0.10000000149011612, 0.20000000298023224]) !=
[Row(b=[0.10000000149011612, 0.20000000298023224])]
```
.
Instead, we compare `dtypes` and the actual data in Row.
--
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]