From 5c012746ed6fbe877150273d93b33c583a5f30f5 Mon Sep 17 00:00:00 2001 From: Jacan Chaplais Date: Thu, 18 Jul 2024 14:13:40 +0100 Subject: [PATCH 1/4] added latex property to PdgArray #184 --- graphicle/data.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/graphicle/data.py b/graphicle/data.py index 492a466..80318d2 100644 --- a/graphicle/data.py +++ b/graphicle/data.py @@ -1038,6 +1038,9 @@ class PdgArray(base.ArrayBase): .. versionchanged:: 0.2.0 Added internal numpy interfaces for greater interoperability. + .. versionchanged:: 0.4.1 + ``name`` property now gives unicode array. latex property added. + Parameters ---------- data : sequence[int] @@ -1045,7 +1048,7 @@ class PdgArray(base.ArrayBase): Attributes ---------- - name : ndarray[object] + name : ndarray[unicode] String representation of particle names. charge : ndarray[float64] Charge for each particle in elementary units. @@ -1069,6 +1072,8 @@ class PdgArray(base.ArrayBase): Spatial parity for each particle. charge_parity : ndarray[float64] Charge parity for each particle. + latex : list[str] + LaTeX compatible representation of particle names. Methods ------- @@ -1235,7 +1240,13 @@ def __get_prop_range(self, field: str) -> base.VoidVector: @property def name(self) -> base.ObjVector: - return self.__get_prop("name") + # 19 is the length of longest name + return self.__get_prop("name").astype(" ty.List[str]: + # 32 is the length of longest name + return self.__get_prop("latex").tolist() @property def charge(self) -> base.DoubleVector: From 277acfc5e40c0695545d4e9904fe2a9158d6f381 Mon Sep 17 00:00:00 2001 From: Jacan Chaplais Date: Wed, 11 Sep 2024 16:07:17 +0100 Subject: [PATCH 2/4] TypeAlias annotations in base --- graphicle/base.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/graphicle/base.py b/graphicle/base.py index 8318413..e54b13f 100644 --- a/graphicle/base.py +++ b/graphicle/base.py @@ -31,16 +31,17 @@ "NumericalStabilityWarning", ] -DoubleVector = npt.NDArray[np.float64] -FloatVector = npt.NDArray[np.float32] -ComplexVector = npt.NDArray[np.complex128] -BoolVector = npt.NDArray[np.bool_] -IntVector = npt.NDArray[np.int32] -HalfIntVector = npt.NDArray[np.int16] -ObjVector = npt.NDArray[np.object_] -AnyVector = npt.NDArray[ty.Any] -VoidVector = npt.NDArray[np.void] -MaskLike = ty.Union["MaskBase", BoolVector] +DoubleVector: tyx.TypeAlias = npt.NDArray[np.float64] +FloatVector: tyx.TypeAlias = npt.NDArray[np.float32] +ComplexVector: tyx.TypeAlias = npt.NDArray[np.complex128] +BoolVector: tyx.TypeAlias = npt.NDArray[np.bool_] +IntVector: tyx.TypeAlias = npt.NDArray[np.int32] +HalfIntVector: tyx.TypeAlias = npt.NDArray[np.int16] +ObjVector: tyx.TypeAlias = npt.NDArray[np.object_] +StringVector: tyx.TypeAlias = npt.NDArray[np.str_] +AnyVector: tyx.TypeAlias = npt.NDArray[ty.Any] +VoidVector: tyx.TypeAlias = npt.NDArray[np.void] +MaskLike: tyx.TypeAlias = ty.Union["MaskBase", BoolVector] DoubleUfunc = ty.TypeVar("DoubleUfunc", DoubleVector, np.float64) DataType = ty.TypeVar("DataType") From 6416e5f16e50d839fbe38449ab4c9c3454864bb6 Mon Sep 17 00:00:00 2001 From: Jacan Chaplais Date: Wed, 11 Sep 2024 16:07:51 +0100 Subject: [PATCH 3/4] added latex and implemented StringVector outputs --- graphicle/data.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/graphicle/data.py b/graphicle/data.py index 80318d2..e35b554 100644 --- a/graphicle/data.py +++ b/graphicle/data.py @@ -1239,14 +1239,14 @@ def __get_prop_range(self, field: str) -> base.VoidVector: return props # type: ignore @property - def name(self) -> base.ObjVector: + def name(self) -> base.StringVector: # 19 is the length of longest name - return self.__get_prop("name").astype(" ty.List[str]: + def latex(self) -> base.StringVector: # 32 is the length of longest name - return self.__get_prop("latex").tolist() + return self.__get_prop("latex").astype(np.str_) @property def charge(self) -> base.DoubleVector: @@ -1265,8 +1265,8 @@ def mass_bounds(self) -> base.VoidVector: return range_arr @property - def quarks(self) -> base.ObjVector: - return self.__get_prop("quarks") + def quarks(self) -> base.StringVector: + return self.__get_prop("quarks").astype(np.str_) @property def width(self) -> base.DoubleVector: From 284e90b3cdc9383cb972fc909997606ee6ddc523 Mon Sep 17 00:00:00 2001 From: Jacan Chaplais Date: Wed, 11 Sep 2024 16:24:36 +0100 Subject: [PATCH 4/4] added missing typing extensions import --- graphicle/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/graphicle/base.py b/graphicle/base.py index e54b13f..101f1d3 100644 --- a/graphicle/base.py +++ b/graphicle/base.py @@ -11,6 +11,7 @@ import numpy as np import numpy.typing as npt +import typing_extensions as tyx __all__ = [ "DoubleVector",