Repository navigation
Fix data recorders' handling of empty snapshots - #4168
Merged
Merged
Conversation
- DataRecorder: an overwrite only replaces the last block if it holds the same time. When a run ended with an empty agent snapshot, which stores no block, the next run's overwrite removed the previous time's data instead. - JSONDataRecorder: a snapshot taken without agents no longer adds a row with value=[] and NaN ids. - JSON, Parquet and SQL recorders return an empty frame with a time column when nothing has been recorded, as DataRecorder does. The scenario runner rejects a frame without columns as a failed outcome. Part of mesa#4165. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Performance benchmarks:
|
quaquel
approved these changes
Nov 22, 2026
quaquel
added a commit
to quaquel/mesa
that referenced
this pull request
Nov 22, 2026
- Add TableDataSet.get_rows_since(index), so BaseDataRecorder only tracks the cursor and no longer imports TableDataSet. The recorder looks the method up on the dataset's type, so only dataset classes that define it qualify. - Document that window_size keeps the rows of the last N collections for a TableDataSet. - Add a test that adds rows on only some steps and runs twice. - Drop the dropna in the table test now that mesa#4168 is merged. - Import TableDataSet at the top of the test module. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RbrUQUQAArrpH7rYQFt6KW
quaquel
added a commit
that referenced
this pull request
Nov 25, 2026
* Fix TableDataSet rows being duplicated by data recorders TableDataSet.data returns its live, append-only rows list. The recorders stored it by reference on every collection, so all stored blocks aliased the same list, and even with a copy each collection re-recorded the full table (1+2+...+n rows with wrong timestamps). BaseDataRecorder now takes a snapshot via _take_snapshot(): for a TableDataSet it returns a new list holding only the rows added since the previous collection (re-including the replaced block's rows on an overwrite). Row dicts are shared with the dataset rather than copied, since neither the dataset nor the recorders mutate them; the TableDataSet.data docstring documents this. Other datasets are unchanged. Adds a regression test across DataRecorder, JSONDataRecorder, ParquetDataRecorder and SQLDataRecorder. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RbrUQUQAArrpH7rYQFt6KW * Address review feedback on TableDataSet recording - Add TableDataSet.get_rows_since(index), so BaseDataRecorder only tracks the cursor and no longer imports TableDataSet. The recorder looks the method up on the dataset's type, so only dataset classes that define it qualify. - Document that window_size keeps the rows of the last N collections for a TableDataSet. - Add a test that adds rows on only some steps and runs twice. - Drop the dropna in the table test now that #4168 is merged. - Import TableDataSet at the top of the test module. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RbrUQUQAArrpH7rYQFt6KW * Never overwrite rows of append-only datasets Collecting again at an already recorded time (for example, the end of a run followed by collect()) made the next recording of that time an overwrite. The backends delete what is stored for that time on an overwrite, but the cursor only re-supplied rows from the latest collection, so rows were lost (e.g., run_for(2), collect(), run_for(1) dropped the t=2 row in DataRecorder, ParquetDataRecorder and SQLDataRecorder). Rows of an append-only dataset never change once added, so an overwrite has nothing to correct. The recorder now skips overwrites for such datasets and only records rows it has not recorded yet, tracked with a single forward-only counter per dataset. _is_append_only() holds the class-level get_rows_since check. Adds a regression test for the case above across all four recorders. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RbrUQUQAArrpH7rYQFt6KW * Record datasets through a single method on all collection paths The time-change, run-end and manual collect() paths each decided whether to overwrite, took a snapshot and stored it. The rule that append-only datasets are never overwritten lived only in the first two; collect() did not need it because it never overwrites. Move these steps into _record_dataset(), used by all three paths. This changes no behavior today, but keeps the rule in one place: once collect() overwrites at an already recorded time (as #4148 proposes), a table's recorded rows would otherwise be deleted at that time while the snapshot only holds the new rows. Adds a test that an overwrite never deletes the recorded rows of an append-only dataset, across all four recorders. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01RbrUQUQAArrpH7rYQFt6KW --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
EwoutH
pushed a commit
that referenced
this pull request
Nov 26, 2026
- DataRecorder: an overwrite only replaces the last block if it holds the same time. When a run ended with an empty agent snapshot, which stores no block, the next run's overwrite removed the previous time's data instead. - JSONDataRecorder: a snapshot taken without agents no longer adds a row with value=[] and NaN ids. - JSON, Parquet and SQL recorders return an empty frame with a time column when nothing has been recorded, as DataRecorder does. The scenario runner rejects a frame without columns as a failed outcome. Part of #4165. Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Jan Kwakkel <[email protected]> Adapted for 3.5.x: 3.5 recorders do not record when a run ends (#4041 is 4.0-only), so an overwrite of the last block never happens and the DataRecorder part is dropped, with its test and the test_run_ended test that main has next to it. The JSONDataRecorder empty-snapshot fix and the empty frame with a time column for the JSON, Parquet and SQL recorders are taken unchanged. (cherry picked from commit be399e6) Assisted-by: Claude Opus 5.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pre-PR Checklist
Summary
Fixes three bugs in
mesa/experimental/data_collectionthat involve empty snapshots. One loses recorded data, one adds rows that were never recorded, and one makes the scenario runner reject a valid run. These are items 1, 4 and 7 of #4165.Bug / Issue
Part of #4165, which has a reproduction script and its output on
main.DataRecorder: when a run ends with an empty agent snapshot, which stores no block, the next run overwrites that time by popping the last block without checking its time. That deletes the previous time's data, and repeated runs can erase the history one block at a time.JSONDataRecorder.get_table_dataframe: every empty agent snapshot becomes a row withvalue=[]and NaN ids, which also turns integer ids into floats.RunConfigurationraisesOutcomeExtractionExceptionfor such a frame, so the run fails.DataRecorderalready returns a frame with atimecolumn.Implementation
DataRecorder._store_dataset_snapshot: on an overwrite, only pop the last block if it holds the same time.JSONDataRecorder.get_table_dataframe: skip empty list snapshots, and returnpd.DataFrame(columns=["time"])when there are no records.ParquetDataRecorder.get_table_dataframeandSQLDataRecorder.get_table_dataframe: returnpd.DataFrame(columns=["time"])when nothing has been stored.Testing
One regression test per bug in
tests/experimental/test_datarecorder.py. Each fails onmainand passes with the fix. The existing data collection, scenario and example tests pass unchanged.Additional Notes
TableDataSetsnapshots common, so 1 and 4 also affect table data there; with both PRs applied, they no longer do.🤖 Generated with Claude Code