This is an automated email from the ASF dual-hosted git repository.
gaogaotiantian pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new f861c618d3ff [SPARK-60155][PYTHON][TEST] Add tests for
pyspark.ml.linalg.VectorUDT
f861c618d3ff is described below
commit f861c618d3ffef68857bb29835d4c8c6f5dd312d
Author: mix060514 <[email protected]>
AuthorDate: Wed Oct 28 16:39:49 2026 -0700
[SPARK-60155][PYTHON][TEST] Add tests for pyspark.ml.linalg.VectorUDT
### What changes were proposed in this pull request?
To expand test coverage to 100% for pyspark.ml.linalg.VectorUDT
I added tests for invalid objects in serialization and invalid lengths and
types in deserialization. I also added a test for simpleString to bring
VectorUDT coverage to 100%.
### Why are the changes needed?
I want to finish covering this part so other contributors can focus on
other areas.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
All VectorUDTTests tests passed.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: GPT-6 Astra
Closes #59363 from mix060514/SPARK-60155.
Authored-by: mix060514 <[email protected]>
Signed-off-by: Tian Gao <[email protected]>
(cherry picked from commit f2c46561941f66f56a4a6b8e1e52876d944eb2e1)
Signed-off-by: Tian Gao <[email protected]>
---
python/pyspark/ml/tests/test_linalg.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/python/pyspark/ml/tests/test_linalg.py
b/python/pyspark/ml/tests/test_linalg.py
index 5b6677088ab7..f24380403392 100644
--- a/python/pyspark/ml/tests/test_linalg.py
+++ b/python/pyspark/ml/tests/test_linalg.py
@@ -338,6 +338,18 @@ class VectorUDTTests(MLlibTestCase):
for v in [self.dv0, self.dv1, self.sv0, self.sv1]:
self.assertEqual(v, self.udt.deserialize(self.udt.serialize(v)))
+ def test_serialization_invalid_object(self):
+ invalid_object = [1.0, 2.0]
+
+ with self.assertRaises(TypeError):
+ self.udt.serialize(invalid_object)
+
+ def test_deserialization_invalid_type(self):
+ invalid_type = 2
+
+ with self.assertRaises(ValueError):
+ self.udt.deserialize((invalid_type, None, None, [1.0, 2.0]))
+
def test_infer_schema(self):
rdd = self.sc.parallelize(
[Row(label=1.0, features=self.dv1), Row(label=0.0,
features=self.sv1)]
@@ -415,6 +427,10 @@ class VectorUDTTests(MLlibTestCase):
def test_hashable(self):
_ = hash(VectorUDT())
+ def test_simple_string(self):
+ result = self.udt.simpleString()
+ self.assertEqual(result, "vector")
+
class MatrixUDTTests(MLlibTestCase):
dm1 = DenseMatrix(3, 2, [0, 1, 4, 5, 9, 10])
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]