Skip to content

Commit

Permalink
Fix bug where TrajectoryWriter.history didn't work for unstructured…
Browse files Browse the repository at this point in the history
… data (i.e a single value per step).

PiperOrigin-RevId: 358177758
Change-Id: I75d5a0d9ccbdb90219f0509ef00f292ca50007c0
  • Loading branch information
acassirer authored and copybara-github committed Feb 18, 2021
1 parent 909c27f commit 2d71d02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion reverb/trajectory_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def history(self):
Raises:
RuntimeError: If `append` hasn't been called at least once before.
"""
if self._structure is None:
if not self._column_history:
raise RuntimeError(
'history cannot be accessed before `append` is called at least once.')

Expand Down
8 changes: 8 additions & 0 deletions reverb/trajectory_writer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ def test_history_require_append_to_be_called_before(self):
with self.assertRaises(RuntimeError):
_ = self.writer.history

def test_history_contains_references_when_data_flat(self):
self.writer.append(1)
self.writer.append(2)
self.writer.append(3)

history = tree.map_structure(extract_data, self.writer.history)
self.assertListEqual(history, [1, 2, 3])

def test_history_contains_structured_references(self):
self.writer.append({'x': 1, 'y': 100})
self.writer.append({'x': 2, 'y': 101})
Expand Down

0 comments on commit 2d71d02

Please sign in to comment.