Skip to content

Commit

Permalink
💄 ui(vecs): improve space str repr (#358)
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Starkman <[email protected]>
nstarman authored Jan 25, 2025

Verified

This commit was signed with the committer’s verified signature. The key has expired.
binghe Chun Tian
1 parent 3525e2c commit f89da37
Showing 3 changed files with 29 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/coordinax/_src/frames/coordinate.py
Original file line number Diff line number Diff line change
@@ -122,7 +122,10 @@ def __str__(self) -> str:
... cx.frames.ICRS())
>>> print(coord)
Coordinate(
data=Space({ 'length': CartesianPos3D( ... ) }),
data=Space({
'length': <CartesianPos3D (x[kpc], y[kpc], z[kpc])
[1 2 3]>
}),
frame=ICRS()
)
28 changes: 24 additions & 4 deletions src/coordinax/_src/vectors/space/core.py
Original file line number Diff line number Diff line change
@@ -353,12 +353,32 @@ def __repr__(self) -> str:
"""
cls_name = self.__class__.__name__
data = "{\n" + indent(repr(self._data)[1:-1], " ")
return cls_name + "(" + data + "\n})"
data = "{\n" + indent(repr(self._data)[1:-1], " ") + "\n}"
return cls_name + "(" + data + ")"

def __str__(self) -> str:
"""Return the string representation."""
return repr(self)
"""Return the string representation.
Examples
--------
>>> import coordinax as cx
>>> q = cx.CartesianPos3D.from_([1, 2, 3], "m")
>>> p = cx.CartesianVel3D.from_([4, 5, 6], "m/s")
>>> w = cx.Space(length=q, speed=p)
>>> print(w)
Space({
'length': <CartesianPos3D (x[m], y[m], z[m])
[1 2 3]>,
'speed': <CartesianVel3D (d_x[m / s], d_y[m / s], d_z[m / s])
[4 5 6]>
})
"""
cls_name = self.__class__.__name__
kv = (f"{k!r}: {v!s}" for k, v in self._data.items())
data = "{\n" + indent(",\n".join(kv), " ") + "\n}"
return cls_name + "(" + data + ")"

# ===============================================================
# Collection
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f89da37

Please sign in to comment.