From 6ebd165cf54ddcfd8615f21004b02d7914b41723 Mon Sep 17 00:00:00 2001 From: pandyah5 Date: Sat, 19 Oct 2024 16:57:23 -0700 Subject: [PATCH 1/3] Added examples for azimuthal and longitudinal properties in 3D and 4D --- src/vector/backends/numpy.py | 78 ++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/src/vector/backends/numpy.py b/src/vector/backends/numpy.py index 69f6488f..920167fa 100644 --- a/src/vector/backends/numpy.py +++ b/src/vector/backends/numpy.py @@ -1424,14 +1424,44 @@ def __repr__(self) -> str: @property 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 + """ + Returns the azimuthal type class for the given ``VectorNumpy3D`` object. + + Example: + >>> import vector + >>> vec = vector.array( + ... [ + ... (1.1, 2.1, 3.1), + ... (1.2, 2.2, 3.2), + ... (1.3, 2.3, 3.3), + ... (1.4, 2.4, 4.4), + ... (1.5, 2.5, 5.5) + ... ], dtype=[("x", float), ("y", float), ("z", float)] + ... ) + >>> print(vec.azimuthal) + [(1.1, 2.1) (1.2, 2.2) (1.3, 2.3) (1.4, 2.4) (1.5, 2.5)] + """ 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 + """ + Returns the longitudinal type class for the given ``VectorNumpy3D`` object. + + Example: + >>> import vector + >>> vec = vector.array( + ... [ + ... (1.1, 2.1, 3.1), + ... (1.2, 2.2, 3.2), + ... (1.3, 2.3, 3.3), + ... (1.4, 2.4, 4.4), + ... (1.5, 2.5, 5.5) + ... ], dtype=[("x", float), ("y", float), ("z", float)] + ... ) + >>> print(vec.longitudinal) + [(3.1,) (3.2,) (3.3,) (4.4,) (5.5,)] + """ return self.view(self._longitudinal_type) def _wrap_result( @@ -1704,14 +1734,46 @@ def __repr__(self) -> str: @property 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 + """ + Returns the azimuthal type class for the given ``VectorNumpy4D`` object. + + Example: + >>> import vector + >>> # Create a 4D vector array with (x, y, z, t) components + >>> vec_4d = vector.array( + ... [ + ... (1.1, 2.1, 3.1, 4.1), + ... (1.2, 2.2, 3.2, 4.2), + ... (1.3, 2.3, 3.3, 4.3), + ... (1.4, 2.4, 3.4, 4.4), + ... (1.5, 2.5, 3.5, 4.5) + ... ], dtype=[("x", float), ("y", float), ("z", float), ("t", float)] + ... ) + >>> print(vec_4d.azimuthal) + [(1.1, 2.1) (1.2, 2.2) (1.3, 2.3) (1.4, 2.4) (1.5, 2.5)] + """ 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 + """ + Returns the longitudinal type class for the given ``Vectornumpy4D`` object. + + Example: + >>> import vector + >>> # Create a 4D vector array with (x, y, z, t) components + >>> vec_4d = vector.array( + ... [ + ... (1.1, 2.1, 3.1, 4.1), + ... (1.2, 2.2, 3.2, 4.2), + ... (1.3, 2.3, 3.3, 4.3), + ... (1.4, 2.4, 3.4, 4.4), + ... (1.5, 2.5, 3.5, 4.5) + ... ], dtype=[("x", float), ("y", float), ("z", float), ("t", float)] + ... ) + >>> print(vec_4d.longitudinal) + [(3.1,) (3.2,) (3.3,) (3.4,) (3.5,)] + """ return self.view(self._longitudinal_type) @property From bfb104b6657a8f8b3a114359db3b54e469074f47 Mon Sep 17 00:00:00 2001 From: pandyah5 Date: Sat, 26 Oct 2024 18:10:21 -0700 Subject: [PATCH 2/3] Remove comments in examples and update output statements --- src/vector/backends/numpy.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/vector/backends/numpy.py b/src/vector/backends/numpy.py index 920167fa..5bd078f8 100644 --- a/src/vector/backends/numpy.py +++ b/src/vector/backends/numpy.py @@ -1438,8 +1438,9 @@ def azimuthal(self) -> AzimuthalNumpy: ... (1.5, 2.5, 5.5) ... ], dtype=[("x", float), ("y", float), ("z", float)] ... ) - >>> print(vec.azimuthal) - [(1.1, 2.1) (1.2, 2.2) (1.3, 2.3) (1.4, 2.4) (1.5, 2.5)] + >>> vec.azimuthal + AzimuthalNumpyXY([(1.1, 2.1), (1.2, 2.2), (1.3, 2.3), (1.4, 2.4), + (1.5, 2.5)], dtype=[('x', ' LongitudinalNumpy: ... (1.5, 2.5, 5.5) ... ], dtype=[("x", float), ("y", float), ("z", float)] ... ) - >>> print(vec.longitudinal) - [(3.1,) (3.2,) (3.3,) (4.4,) (5.5,)] + >>> vec.longitudinal + LongitudinalNumpyZ([(3.1,), (3.2,), (3.3,), (4.4,), (5.5,)], + dtype=[('z', ' AzimuthalNumpy: Example: >>> import vector - >>> # Create a 4D vector array with (x, y, z, t) components >>> vec_4d = vector.array( ... [ ... (1.1, 2.1, 3.1, 4.1), @@ -1749,19 +1750,19 @@ def azimuthal(self) -> AzimuthalNumpy: ... (1.5, 2.5, 3.5, 4.5) ... ], dtype=[("x", float), ("y", float), ("z", float), ("t", float)] ... ) - >>> print(vec_4d.azimuthal) - [(1.1, 2.1) (1.2, 2.2) (1.3, 2.3) (1.4, 2.4) (1.5, 2.5)] + >>> vec_4d.azimuthal + AzimuthalNumpyXY([(1.1, 2.1), (1.2, 2.2), (1.3, 2.3), (1.4, 2.4), + (1.5, 2.5)], dtype=[('x', ' LongitudinalNumpy: """ - Returns the longitudinal type class for the given ``Vectornumpy4D`` object. + Returns the longitudinal type class for the given ``VectorNumpy4D`` object. Example: >>> import vector - >>> # Create a 4D vector array with (x, y, z, t) components >>> vec_4d = vector.array( ... [ ... (1.1, 2.1, 3.1, 4.1), @@ -1771,8 +1772,9 @@ def longitudinal(self) -> LongitudinalNumpy: ... (1.5, 2.5, 3.5, 4.5) ... ], dtype=[("x", float), ("y", float), ("z", float), ("t", float)] ... ) - >>> print(vec_4d.longitudinal) - [(3.1,) (3.2,) (3.3,) (3.4,) (3.5,)] + >>> vec_4d.longitudinal + LongitudinalNumpyZ([(3.1,), (3.2,), (3.3,), (3.4,), (3.5,)], + dtype=[('z', ' Date: Sun, 27 Oct 2024 13:02:27 +0100 Subject: [PATCH 3/3] Apply suggestions from code review --- src/vector/backends/numpy.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vector/backends/numpy.py b/src/vector/backends/numpy.py index 5bd078f8..da6a6af3 100644 --- a/src/vector/backends/numpy.py +++ b/src/vector/backends/numpy.py @@ -1741,7 +1741,7 @@ def azimuthal(self) -> AzimuthalNumpy: Example: >>> import vector - >>> vec_4d = vector.array( + >>> vec = vector.array( ... [ ... (1.1, 2.1, 3.1, 4.1), ... (1.2, 2.2, 3.2, 4.2), @@ -1750,7 +1750,7 @@ def azimuthal(self) -> AzimuthalNumpy: ... (1.5, 2.5, 3.5, 4.5) ... ], dtype=[("x", float), ("y", float), ("z", float), ("t", float)] ... ) - >>> vec_4d.azimuthal + >>> vec.azimuthal AzimuthalNumpyXY([(1.1, 2.1), (1.2, 2.2), (1.3, 2.3), (1.4, 2.4), (1.5, 2.5)], dtype=[('x', ' LongitudinalNumpy: Example: >>> import vector - >>> vec_4d = vector.array( + >>> vec = vector.array( ... [ ... (1.1, 2.1, 3.1, 4.1), ... (1.2, 2.2, 3.2, 4.2), @@ -1772,7 +1772,7 @@ def longitudinal(self) -> LongitudinalNumpy: ... (1.5, 2.5, 3.5, 4.5) ... ], dtype=[("x", float), ("y", float), ("z", float), ("t", float)] ... ) - >>> vec_4d.longitudinal + >>> vec.longitudinal LongitudinalNumpyZ([(3.1,), (3.2,), (3.3,), (3.4,), (3.5,)], dtype=[('z', '