Skip to content

Conversation

@Saransh-cpp
Copy link
Member

@Saransh-cpp Saransh-cpp commented Oct 21, 2025

Description

Fixes #600
Fixes #641

Removes Python 3.9 support:

  • be explicit about zip being strict
  • update typing syntax
  • type ignore numpy ufunc calls for object and sympy vectors
  • fix getitem signature for numpy vectors and coordinate classes
  • explicit type ignores for momentum numpy classes

Bumps the minimum Numba version (supported from Python 3.9):

  • remove local nan_to_num definition

Checklist

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't any other open Pull Requests for the required change?
  • Does your submission pass pre-commit? ($ pre-commit run --all-files or $ nox -s lint)
  • Does your submission pass tests? ($ pytest or $ nox -s tests)
  • Does the documentation build with your changes? ($ cd docs; make clean; make html or $ nox -s docs)
  • Does your submission pass the doctests? ($ pytest --doctest-plus src/vector/ or $ nox -s doctests)

Before Merging

  • Summarize the commit messages into a brief review of the Pull request.

@Saransh-cpp Saransh-cpp marked this pull request as draft October 21, 2025 15:17
@Saransh-cpp Saransh-cpp force-pushed the saransh/rm-Python-3.9 branch from c5983dc to 7a16de2 Compare December 28, 2025 17:39
@Saransh-cpp Saransh-cpp marked this pull request as ready for review December 28, 2025 17:43
Comment on lines -54 to -55
@numba.extending.overload(numpy.nan_to_num) # FIXME: This needs to go into Numba!
def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to Numba a while back

Comment on lines 193 to +206
def _getitem(
array: VectorNumpy2D | VectorNumpy3D | VectorNumpy4D,
array: VectorNumpy2D
| VectorNumpy3D
| VectorNumpy4D
| AzimuthalNumpyRhoPhi
| AzimuthalNumpyXY
| LongitudinalNumpyZ
| LongitudinalNumpyTheta
| LongitudinalNumpyEta
| TemporalNumpyT
| TemporalNumpyTau,
where: typing.Any,
is_momentum: bool,
) -> float | FloatArray:
) -> float | FloatArray | VectorProtocol | Azimuthal | Longitudinal | Temporal:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also implements __getitem__ for NumPy coordinate types. Updating the type signature allowed me to remove a few type: ignore[arg-type] comments in the function body.

Comment on lines +411 to +422
def __getitem__(
self, where: int
) -> VectorProtocol | Azimuthal | Longitudinal | Temporal: ...

@typing.overload
def __getitem__(
self, where: typing.Any
) -> float | FloatArray | VectorProtocol | Azimuthal | Longitudinal | Temporal: ...

def __getitem__(self, where: typing.Any) -> float | FloatArray:
def __getitem__(
self, where: typing.Any
) -> float | FloatArray | VectorProtocol | Azimuthal | Longitudinal | Temporal:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated overloads as per the updates to the actual function (see above)



class MomentumNumpy2D(PlanarMomentum, VectorNumpy2D):
class MomentumNumpy2D(PlanarMomentum, VectorNumpy2D): # type: ignore[misc]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type: ignore[misc] comments were already present in VectorNumpy*D definitions, but now they are also required for Momentum classes.

@Saransh-cpp Saransh-cpp changed the title Remove support for Python 3.9 chore: rm support for Python 3.9 + bump Numba Dec 28, 2025
@Saransh-cpp
Copy link
Member Author

@henryiii, @pfackeldey, could you please take a look whenever you are free (after the holidays 🎄)? Thanks!

@ikrommyd
Copy link

ikrommyd commented Jan 4, 2026

I was actually just looking into making a PR to drop 3.9 so it's good to see that this was already done. I was gonna add 3.14 testing though since I noticed that the ci matrix does not test against 3.14. Do you wanna do it in this PR or should I open a separate one?

@ikrommyd
Copy link

ikrommyd commented Jan 4, 2026

You would need to change a test for 3.14 support. I'm attempting to run the vector tests with 3.14 here scikit-hep/integration-tests#14 and I'm hitting this.

     def test_VectorObjectType():
        # These tests verify that the reference counts for Python objects touched in
        # the lowered Numba code do not increase or decrease with the number of times
        # the function is run.
    
        @numba.njit
        def zero(obj):
            return None
    
        @numba.njit
        def one(obj):
            return obj
    
        @numba.njit
        def two(obj):
            return obj, obj
    
        obj = vector.obj(x=1, y=2)
>       assert (sys.getrefcount(obj), sys.getrefcount(obj.azimuthal)) == (2, 2)
E       assert (1, 2) == (2, 2)
E         
E         At index 0 diff: 1 != 2
E         
E         Full diff:
E           (
E         -     2,
E         ?     ^
E         +     1,
E         ?     ^
E               2,
E           )

@Saransh-cpp
Copy link
Member Author

Ooh, I think we somehow missed that, thanks, @ikrommyd! I can quickly create a new PR to fix this.

Saransh-cpp and others added 5 commits January 5, 2026 03:33
* be explicit about zip being strict
* update syntax
* type ignore numpy ufunc calls for object and sympy vectors
* fix getitem signature for numpy vectors and coordinate classes
@Saransh-cpp Saransh-cpp force-pushed the saransh/rm-Python-3.9 branch from 460b386 to acc68c4 Compare January 4, 2026 22:03
@ikrommyd
Copy link

ikrommyd commented Jan 4, 2026

Ooh, I think we somehow missed that, thanks, @ikrommyd! I can quickly create a new PR to fix this.

Thanks! If you don't have time and want me to do it, let me know. For awkward, we treated numba refcount differences like this in 3.14: https://github.com/scikit-hep/awkward/pull/3757/changes

@Saransh-cpp Saransh-cpp mentioned this pull request Jan 4, 2026
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove Python 3.8 and 3.9 support Replace custom nan_to_num with Numba's implementation

3 participants