Skip to content
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

[jiminy_py] Fix 'tree.unflatten_as' mixing up key order for 'gym.spaces.Dict'. #819

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions python/jiminy_py/src/jiminy_py/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from functools import lru_cache
from itertools import chain, starmap
from collections.abc import (Mapping, ValuesView, Sequence, Set)
from collections import OrderedDict
from typing import (
Any, Union, Mapping as MappingT, Iterable, Iterator as Iterator, Tuple,
TypeVar, Callable, Type)
Expand Down Expand Up @@ -173,10 +174,10 @@ def _unflatten_as(data: StructNested[Any],
"""
data_type = type(data)
if issubclass_mapping(data_type): # type: ignore[arg-type]
return data_type({ # type: ignore[call-arg]
return data_type(OrderedDict({ # type: ignore[call-arg]
duburcqa marked this conversation as resolved.
Show resolved Hide resolved
key: _unflatten_as(value, data_leaf_it)
for key, value in data.items() # type: ignore[union-attr]
})
}))
if issubclass_sequence(data_type): # type: ignore[arg-type]
return data_type(tuple( # type: ignore[call-arg]
_unflatten_as(value, data_leaf_it) for value in data
Expand Down
Loading