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: [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]

Reply via email to