bearomorphism opened a new pull request, #59390:
URL: https://github.com/apache/spark/pull/59390
### What changes were proposed in this pull request?
- Add `__getitem__(self, index: int) -> np.float64` to the MLlib `Vector`
base interface, following its existing `NotImplementedError` pattern.
- Remove the indexing type ignore from LIBSVM conversion without changing
the conversion logic.
- Add a typing regression test for base-vector indexing, dense/sparse scalar
indexing, and dense-vector slicing.
### Why are the changes needed?
Both concrete vector classes support integer indexing, but the base
interface does not declare it. Mypy therefore rejects indexing values annotated
as `Vector`, requiring an unnecessary suppression in `MLUtils`.
### Does this PR introduce _any_ user-facing change?
Static type checkers now recognize integer indexing through `Vector`.
Concrete vector indexing and LIBSVM output are unchanged.
### How was this patch tested?
- Confirmed the new typing test reports that `Vector` is not indexable
before the fix; it passes after the fix.
- Mypy passed on both changed modules with a clean, non-incremental check.
- Existing `VectorTests` in `pyspark.mllib.tests.test_linalg` and
`MLUtilsTests` in `pyspark.mllib.tests.test_util` passed.
- Ruff lint/format checks and `git diff --check` passed.
Typing regression command:
```bash
MYPYPATH=python pytest -q -o 'python_files=test_*.yml' --rootdir python \
--mypy-only-local-stub --mypy-ini-file python/mypy.ini \
python/pyspark/tests/typing/test_mllib_linalg.yml
```
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: pi 1.1.0 with OpenAI gpt-6-astra
--
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]