Skip to content

Commit

Permalink
Batch.to_dict should be a rremain by default a recursive conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
dantp-ai committed Apr 16, 2024
1 parent 91abd6b commit def4f0d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/base/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def test_to_dict_nested_batch_no_recurse() -> None:
nested_batch = Batch(c=3)
batch = Batch(a=1, b=nested_batch)
expected = {"a": np.asanyarray(1), "b": nested_batch}
assert not DeepDiff(batch.to_dict(), expected)
assert not DeepDiff(batch.to_dict(recurse=False), expected)

@staticmethod
def test_to_dict_nested_batch_recurse() -> None:
Expand Down
4 changes: 2 additions & 2 deletions tianshou/data/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def split(
"""
...

def to_dict(self, recurse: bool = False) -> dict[str, Any]:
def to_dict(self, recurse: bool = True) -> dict[str, Any]:
...

def to_list_of_dicts(self) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -442,7 +442,7 @@ def __init__(
# Feels like kwargs could be just merged into batch_dict in the beginning
self.__init__(kwargs, copy=copy) # type: ignore

def to_dict(self, recurse: bool = False) -> dict[str, Any]:
def to_dict(self, recurse: bool = True) -> dict[str, Any]:
result = {}
for k, v in self.__dict__.items():
if recurse and isinstance(v, Batch):
Expand Down

0 comments on commit def4f0d

Please sign in to comment.