Skip to content

Commit 4c6e321

Browse files
committed
fix: accept list as rot_vec argument in Rotation constructor
1 parent 7b9bdb4 commit 4c6e321

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 0.3.4
4+
### Fix
5+
- Fix bug accepting `rot_vec` argument in `Rotation` as list.
6+
37
## 0.3.3
48
### Add
59
- Update Rotation type to include support for definition using either quaternions, angle axis or matrix.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "research-ktree"
3-
version = "0.3.3"
3+
version = "0.3.4"
44
description = "Research python kinematic library"
55
authors = ["Daniel Lemus <dlemus@rocsys.com>"]
66
readme = "README.md"

src/ktree/k_types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ class Rotation(BaseModel):
242242
def _rpy_validator(cls, rpy_value: NDArray[np.float_] | list[float] | None, info: ValidationInfo) -> NDArray:
243243
return _validate_list(rpy_value) if rpy_value is not None else rpy_value
244244

245+
@field_validator("rot_vec", mode="before")
246+
@classmethod
247+
def _rot_vec_validator(cls, rot_vec: NDArray[np.float_] | list[float] | None, info: ValidationInfo) -> NDArray:
248+
return _validate_list(rot_vec) if rot_vec is not None else rot_vec
249+
245250
@model_validator(mode="wrap") # type: ignore[misc]
246251
def _validator(self, handler: ValidatorFunctionWrapHandler) -> Self:
247252
if isinstance(self, dict):

test/test_types.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,16 @@ def test_rotation() -> None:
5959
assert np.allclose(r.quaternion.vector, baseR.as_quat())
6060
assert np.allclose(r.rot_vec, baseR.as_rotvec())
6161

62-
r = Rotation()
63-
r.matrix = R.from_euler("xyz", [rz, ry, rx], degrees=False).as_matrix()
62+
r = Rotation(matrix=R.from_euler("xyz", [rz, ry, rx], degrees=False).as_matrix())
6463

6564
assert np.isclose(r.rx, rz)
6665
assert np.isclose(r.ry, ry)
6766
assert np.isclose(r.rz, rx)
6867

68+
r = Rotation(rot_vec=[0.1, 0.2, 0.3])
69+
70+
assert np.allclose(r.rot_vec, [0.1, 0.2, 0.3])
71+
6972
assert Rotation(rpy=[1.2, 1.3, 1.4]) == Rotation(rpy=[1.2, 1.3, 1.4])
7073

7174

0 commit comments

Comments
 (0)