diff --git a/activitysim/core/workflow/checkpoint.py b/activitysim/core/workflow/checkpoint.py index 7391e1c9b9..b80b3ff70b 100644 --- a/activitysim/core/workflow/checkpoint.py +++ b/activitysim/core/workflow/checkpoint.py @@ -764,12 +764,8 @@ def load(self, checkpoint_name: str, store=None): checkpoints = checkpoints.loc[:i] # if the store is not open in read-only mode, - # write it to the store to ensure so any subsequent checkpoints are forgotten - if ( - store is None - and not self.is_readonly - and isinstance(self.store, pd.HDFStore) - ): + # write it to the store to ensure any subsequent checkpoints are forgotten + if store is None and not self.is_readonly(): self._write_df(checkpoints, CHECKPOINT_TABLE_NAME) except IndexError: diff --git a/activitysim/core/workflow/test/test_checkpoints.py b/activitysim/core/workflow/test/test_checkpoints.py new file mode 100644 index 0000000000..e59c4b795f --- /dev/null +++ b/activitysim/core/workflow/test/test_checkpoints.py @@ -0,0 +1,29 @@ +import pandas as pd + +from activitysim.core.workflow import State + + +def test_parquet_resume_truncates_checkpoint_inventory(tmp_path): + state = State.make_default( + tmp_path, + settings={"checkpoint_format": "parquet"}, + ) + + state.add_table("sample", pd.DataFrame({"value": [1]})) + state.checkpoint.add("target") + + state.add_table("sample", pd.DataFrame({"value": [2]})) + state.checkpoint.add("later") + state.checkpoint.close_store() + + try: + state.checkpoint.restore("target") + + inventory = state.checkpoint.get_inventory() + checkpoint_names = inventory["checkpoint_name"].tolist() + + assert checkpoint_names == ["target"] + assert state.checkpoint.store.list_checkpoint_names() == ["target"] + assert state.get_dataframe("sample")["value"].tolist() == [1] + finally: + state.checkpoint.close_store() \ No newline at end of file