You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zhengruifeng (via GitHub)" <gi...@apache.org> on 2026/08/20 12:46:23 UTC
[PR] [SPARK-58906][ML][PYTHON] Make vector and matrix UDTs singletons [spark]
zhengruifeng opened a new pull request, #58166:
URL: https://github.com/apache/spark/pull/58166
### What changes were proposed in this pull request?
This PR makes the Python ML vector and matrix UDT implementations singletons by using
the existing `DataTypeSingleton` metaclass:
- `pyspark.ml.linalg.VectorUDT`
- `pyspark.ml.linalg.MatrixUDT`
- `pyspark.mllib.linalg.VectorUDT`
- `pyspark.mllib.linalg.MatrixUDT`
It also adds tests that repeated constructor calls and schema JSON round-trips return the
same UDT instance.
This follows the same singleton reuse direction as
https://github.com/apache/spark/pull/57757, which reused the canonical ML vector data
type to avoid repeated equivalent UDT allocations.
### Why are the changes needed?
These UDT classes are stateless. Reusing one Python instance avoids repeated equivalent
allocations and keeps schema round-trips consistent with the singleton behavior already
used by stateless SQL data types.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Added focused tests for both `pyspark.ml.linalg` and `pyspark.mllib.linalg` UDTs.
Also ran:
```
git diff --check
grep -rn -P "[^\x00-\x7F]" python/pyspark/ml/linalg/__init__.py python/pyspark/mllib/linalg/__init__.py python/pyspark/ml/tests/test_linalg.py python/pyspark/mllib/tests/test_linalg.py
awk 'length>100 && $0 !~ /^[[:space:]]*(import|package) / && $0 !~ /https?:\/\// {print FILENAME":"FNR": "length" chars"}' python/pyspark/ml/linalg/__init__.py python/pyspark/mllib/linalg/__init__.py python/pyspark/ml/tests/test_linalg.py python/pyspark/mllib/tests/test_linalg.py
```
The full PySpark test suites were not run locally.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-5)
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58906][ML][PYTHON] Make vector and matrix UDTs singletons [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on PR #58166:
URL: https://github.com/apache/spark/pull/58166#issuecomment-5363462357
**Merge Summary:**
- merged into master https://github.com/apache/spark/commit/0cedfe547eae06097529699268b199f7cd4f7d50
- merged into branch-4.x https://github.com/apache/spark/commit/4937c8ccdd58d3664caf4cd501ff430d0f278b22
*Posted by `merge_spark_pr.py`*
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58906][ML][PYTHON] Make vector and matrix UDTs singletons [spark]
Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b commented on PR #58166:
URL: https://github.com/apache/spark/pull/58166#issuecomment-5362585156
+1!
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-58906][ML][PYTHON] Make vector and matrix UDTs singletons [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng closed pull request #58166: [SPARK-58906][ML][PYTHON] Make vector and matrix UDTs singletons
URL: https://github.com/apache/spark/pull/58166
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org