Skip to content

fix: uncap numpy #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Version 1.5

### Version 1.5.1

#### Fixes

- fix: uncap numpy [#502][]

[#502]: https://github.com/scikit-hep/vector/pull/502

### Version 1.5.0

#### Breaking
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dynamic = [
"version",
]
dependencies = [
"numpy>=1.13.3,<2.1",
"numpy>=1.13.3",
"packaging>=19",
]
optional-dependencies.awkward = [
Expand Down
40 changes: 20 additions & 20 deletions src/vector/backends/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,38 +215,38 @@
)
if hasattr(array, "_longitudinal_type"):
longitudinal = array._longitudinal_type.ObjectClass(
*(out[x] for x in _coordinate_class_to_names[_ltype(array)]) # type: ignore[arg-type]
*(out[x] for x in _coordinate_class_to_names[_ltype(array)])
)
if hasattr(array, "_temporal_type"):
temporal = array._temporal_type.ObjectClass(
*(out[x] for x in _coordinate_class_to_names[_ttype(array)]) # type: ignore[arg-type]
*(out[x] for x in _coordinate_class_to_names[_ttype(array)])
)
if temporal is not None:
return array.ObjectClass(
azimuthal=azimuthal,
longitudinal=longitudinal, # type: ignore[arg-type, return-value]
longitudinal=longitudinal, # type: ignore[arg-type]
temporal=temporal, # type: ignore[arg-type]
)
elif longitudinal is not None:
return array.ObjectClass(azimuthal=azimuthal, longitudinal=longitudinal) # type: ignore[arg-type, return-value]
return array.ObjectClass(azimuthal=azimuthal, longitudinal=longitudinal) # type: ignore[arg-type]
elif azimuthal is not None:
return array.ObjectClass(azimuthal=azimuthal) # type: ignore[return-value]
return array.ObjectClass(azimuthal=azimuthal)
elif issubclass(array.ObjectClass, vector.backends.object.AzimuthalObject):
return array.ObjectClass(*tuple(out)[:2]) # type: ignore[arg-type, return-value]
return array.ObjectClass(*tuple(out)[:2]) # type: ignore[arg-type]
elif issubclass(array.ObjectClass, vector.backends.object.LongitudinalObject):
coords = (
out.view(numpy.ndarray)[0]
if len(out) == 1 # type: ignore[arg-type]
else out.view(numpy.ndarray)[2]
)
return array.ObjectClass(coords) # type: ignore[return-value]
return array.ObjectClass(coords)
else:
coords = (
out.view(numpy.ndarray)[0]
if len(out) == 1 # type: ignore[arg-type]
else out.view(numpy.ndarray)[3]
)
return array.ObjectClass(coords) # type: ignore[return-value]
return array.ObjectClass(coords)


def _array_repr(
Expand Down Expand Up @@ -871,7 +871,7 @@
return typing.cast(
SameVectorNumpyType,
# pylint: disable-next=unexpected-keyword-arg
numpy.sum(

Check warning on line 874 in src/vector/backends/numpy.py

View workflow job for this annotation

GitHub Actions / Check SDist

Useless suppression of 'unexpected-keyword-arg'
self,
axis=axis,
dtype=dtype,
Expand All @@ -879,14 +879,14 @@
keepdims=keepdims,
initial=initial,
where=where,
), # type: ignore[call-overload]
),
)

def __eq__(self, other: typing.Any) -> typing.Any:
return numpy.equal(self, other) # type: ignore[call-overload]
return numpy.equal(self, other)

def __ne__(self, other: typing.Any) -> typing.Any:
return numpy.not_equal(self, other) # type: ignore[call-overload]
return numpy.not_equal(self, other)

def __reduce__(self) -> str | tuple[typing.Any, ...]:
pickled_state = super().__reduce__()
Expand Down Expand Up @@ -1197,7 +1197,7 @@
AzimuthalNumpyXY([(1.1, 2.1), (1.2, 2.2), (1.3, 2.3), (1.4, 2.4),
(1.5, 2.5)], dtype=[('x', '<f8'), ('y', '<f8')])
"""
return self.view(self._azimuthal_type) # type: ignore[return-value]
return self.view(self._azimuthal_type)

def _wrap_result(
self,
Expand Down Expand Up @@ -1305,7 +1305,7 @@
return _setitem(self, where, what, False)


class MomentumNumpy2D(PlanarMomentum, VectorNumpy2D): # type: ignore[misc]
class MomentumNumpy2D(PlanarMomentum, VectorNumpy2D):
"""
Two dimensional momentum vector class for the NumPy backend. This class can be directly
used to construct two dimensional NumPy momentum vectors. For two dimensional
Expand Down Expand Up @@ -1427,13 +1427,13 @@
def azimuthal(self) -> AzimuthalNumpy:
"""Returns the azimuthal type class for the given ``VectorNumpy3D`` object."""
# TODO: Add an example here - see https://github.com/scikit-hep/vector/issues/194
return self.view(self._azimuthal_type) # type: ignore[return-value]
return self.view(self._azimuthal_type)

@property
def longitudinal(self) -> LongitudinalNumpy:
"""Returns the longitudinal type class for the given ``VectorNumpy3D`` object."""
# TODO: Add an example here - see https://github.com/scikit-hep/vector/issues/194
return self.view(self._longitudinal_type) # type: ignore[return-value]
return self.view(self._longitudinal_type)

def _wrap_result(
self,
Expand Down Expand Up @@ -1562,7 +1562,7 @@
return _setitem(self, where, what, False)


class MomentumNumpy3D(SpatialMomentum, VectorNumpy3D): # type: ignore[misc]
class MomentumNumpy3D(SpatialMomentum, VectorNumpy3D):
"""
Three dimensional momentum vector class for the NumPy backend. This class can be directly
used to construct three dimensional NumPy momentum vectors. For three dimensional
Expand Down Expand Up @@ -1707,19 +1707,19 @@
def azimuthal(self) -> AzimuthalNumpy:
"""Returns the azimuthal type class for the given ``VectorNumpy4D`` object."""
# TODO: Add an example here - see https://github.com/scikit-hep/vector/issues/194
return self.view(self._azimuthal_type) # type: ignore[return-value]
return self.view(self._azimuthal_type)

@property
def longitudinal(self) -> LongitudinalNumpy:
"""Returns the longitudinal type class for the given ``Vectornumpy4D`` object."""
# TODO: Add an example here - see https://github.com/scikit-hep/vector/issues/194
return self.view(self._longitudinal_type) # type: ignore[return-value]
return self.view(self._longitudinal_type)

@property
def temporal(self) -> TemporalNumpy:
"""Returns the azimuthal type class for the given ``VectorNumpy4D`` object."""
# TODO: Add an example here - see https://github.com/scikit-hep/vector/issues/194
return self.view(self._temporal_type) # type: ignore[return-value]
return self.view(self._temporal_type)

def _wrap_result(
self,
Expand Down Expand Up @@ -1882,7 +1882,7 @@
return _setitem(self, where, what, False)


class MomentumNumpy4D(LorentzMomentum, VectorNumpy4D): # type: ignore[misc]
class MomentumNumpy4D(LorentzMomentum, VectorNumpy4D):
"""
Four dimensional momentum vector class for the NumPy backend. This class can be directly
used to construct four dimensional NumPy momentum vectors. For three dimensional
Expand Down
36 changes: 18 additions & 18 deletions src/vector/backends/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,61 +332,61 @@ class VectorObject(Vector):
lib = numpy

def __eq__(self, other: typing.Any) -> typing.Any:
return numpy.equal(self, other) # type: ignore[call-overload]
return numpy.equal(self, other)

def __ne__(self, other: typing.Any) -> typing.Any:
return numpy.not_equal(self, other) # type: ignore[call-overload]
return numpy.not_equal(self, other)

def __abs__(self) -> float:
return numpy.absolute(self)

def __add__(self, other: VectorProtocol) -> VectorProtocol:
return numpy.add(self, other) # type: ignore[call-overload]
return numpy.add(self, other)

def __radd__(self, other: VectorProtocol) -> VectorProtocol:
return numpy.add(other, self) # type: ignore[call-overload]
return numpy.add(other, self)

def __iadd__(self: SameVectorType, other: VectorProtocol) -> SameVectorType:
return _replace_data(self, numpy.add(self, other)) # type: ignore[call-overload]
return _replace_data(self, numpy.add(self, other))

def __sub__(self, other: VectorProtocol) -> VectorProtocol:
return numpy.subtract(self, other) # type: ignore[call-overload]
return numpy.subtract(self, other)

def __rsub__(self, other: VectorProtocol) -> VectorProtocol:
return numpy.subtract(other, self) # type: ignore[call-overload]
return numpy.subtract(other, self)

def __isub__(self: SameVectorType, other: VectorProtocol) -> SameVectorType:
return _replace_data(self, numpy.subtract(self, other)) # type: ignore[call-overload]
return _replace_data(self, numpy.subtract(self, other))

def __mul__(self, other: float) -> VectorProtocol:
return numpy.multiply(self, other) # type: ignore[call-overload]
return numpy.multiply(self, other)

def __rmul__(self, other: float) -> VectorProtocol:
return numpy.multiply(other, self) # type: ignore[call-overload]
return numpy.multiply(other, self)

def __imul__(self: SameVectorType, other: float) -> SameVectorType:
return _replace_data(self, numpy.multiply(self, other)) # type: ignore[call-overload]
return _replace_data(self, numpy.multiply(self, other))

def __neg__(self: SameVectorType) -> SameVectorType:
return numpy.negative(self) # type: ignore[call-overload]
return numpy.negative(self)

def __pos__(self: SameVectorType) -> SameVectorType:
return numpy.positive(self) # type: ignore[call-overload]
return numpy.positive(self)

def __truediv__(self, other: float) -> VectorProtocol:
return numpy.true_divide(self, other) # type: ignore[call-overload]
return numpy.true_divide(self, other)

def __rtruediv__(self, other: float) -> VectorProtocol:
return numpy.true_divide(other, self) # type: ignore[call-overload]
return numpy.true_divide(other, self)

def __itruediv__(self: SameVectorType, other: float) -> VectorProtocol:
return _replace_data(self, numpy.true_divide(self, other)) # type: ignore[call-overload]
return _replace_data(self, numpy.true_divide(self, other))

def __pow__(self, other: float) -> float:
return numpy.square(self) if other == 2 else numpy.power(self, other) # type: ignore[call-overload]
return numpy.square(self) if other == 2 else numpy.power(self, other)

def __matmul__(self, other: VectorProtocol) -> float:
return numpy.matmul(self, other) # type: ignore[call-overload]
return numpy.matmul(self, other)

def __array_ufunc__(
self,
Expand Down
36 changes: 18 additions & 18 deletions src/vector/backends/sympy.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,61 +345,61 @@ class VectorSympy(Vector):
lib = SympyLib()

def __eq__(self, other: typing.Any) -> typing.Any:
return numpy.equal(self, other) # type: ignore[call-overload]
return numpy.equal(self, other)

def __ne__(self, other: typing.Any) -> typing.Any:
return numpy.not_equal(self, other) # type: ignore[call-overload]
return numpy.not_equal(self, other)

def __abs__(self) -> float:
return numpy.absolute(self)

def __add__(self, other: VectorProtocol) -> VectorProtocol:
return numpy.add(self, other) # type: ignore[call-overload]
return numpy.add(self, other)

def __radd__(self, other: VectorProtocol) -> VectorProtocol:
return numpy.add(other, self) # type: ignore[call-overload]
return numpy.add(other, self)

def __iadd__(self: SameVectorType, other: VectorProtocol) -> SameVectorType:
return _replace_data(self, numpy.add(self, other)) # type: ignore[call-overload]
return _replace_data(self, numpy.add(self, other))

def __sub__(self, other: VectorProtocol) -> VectorProtocol:
return numpy.subtract(self, other) # type: ignore[call-overload]
return numpy.subtract(self, other)

def __rsub__(self, other: VectorProtocol) -> VectorProtocol:
return numpy.subtract(other, self) # type: ignore[call-overload]
return numpy.subtract(other, self)

def __isub__(self: SameVectorType, other: VectorProtocol) -> SameVectorType:
return _replace_data(self, numpy.subtract(self, other)) # type: ignore[call-overload]
return _replace_data(self, numpy.subtract(self, other))

def __mul__(self, other: float) -> VectorProtocol:
return numpy.multiply(self, other) # type: ignore[call-overload]
return numpy.multiply(self, other)

def __rmul__(self, other: float) -> VectorProtocol:
return numpy.multiply(other, self) # type: ignore[call-overload]
return numpy.multiply(other, self)

def __imul__(self: SameVectorType, other: float) -> SameVectorType:
return _replace_data(self, numpy.multiply(self, other)) # type: ignore[call-overload]
return _replace_data(self, numpy.multiply(self, other))

def __neg__(self: SameVectorType) -> SameVectorType:
return numpy.negative(self) # type: ignore[call-overload]
return numpy.negative(self)

def __pos__(self: SameVectorType) -> SameVectorType:
return numpy.positive(self) # type: ignore[call-overload]
return numpy.positive(self)

def __truediv__(self, other: float) -> VectorProtocol:
return numpy.true_divide(self, other) # type: ignore[call-overload]
return numpy.true_divide(self, other)

def __rtruediv__(self, other: float) -> VectorProtocol:
return numpy.true_divide(other, self) # type: ignore[call-overload]
return numpy.true_divide(other, self)

def __itruediv__(self: SameVectorType, other: float) -> VectorProtocol:
return _replace_data(self, numpy.true_divide(self, other)) # type: ignore[call-overload]
return _replace_data(self, numpy.true_divide(self, other))

def __pow__(self, other: float) -> float:
return numpy.power(self, other) # type: ignore[call-overload]
return numpy.power(self, other)

def __matmul__(self, other: VectorProtocol) -> float:
return numpy.matmul(self, other) # type: ignore[call-overload]
return numpy.matmul(self, other)

def __array_ufunc__(
self,
Expand Down