Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 2 additions & 6 deletions activitysim/core/workflow/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 29 additions & 0 deletions activitysim/core/workflow/test/test_checkpoints.py
Original file line number Diff line number Diff line change
@@ -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()
Loading