Skip to content

Commit 5ce4285

Browse files
committed
fix: clean up pre-existing final output files at the start of merge phase to prevent duplicate rows when resuming from a snapshot
1 parent df5541c commit 5ce4285

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

algorithms/graph/checkpoint.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,17 @@ def merge_checkpoints(output_root: str, checkpoint_folder: str, run_id: str,
224224
row.append(received_replies.get(uid, 0))
225225
row.append(received_mentions.get(uid, 0))
226226

227+
# ── Clean up pre-existing final files to prevent duplicates ─────────
228+
final_ext = ".csv" if final_file_format == "csv" else _ext(final_file_format)
229+
for name in ["user_features", "edges_retweet", "edges_reply", "edges_mention", "screen_name_map"]:
230+
fpath = os.path.join(out_dir, name + final_ext)
231+
if os.path.exists(fpath):
232+
try:
233+
os.remove(fpath)
234+
except Exception as e:
235+
if logger:
236+
logger.warning(f"Could not remove pre-existing final file {fpath}: {e}")
237+
227238
# ── Write final files ────────────────────────────────────────────────
228239
def _out(name: str) -> str:
229240
return os.path.join(out_dir, name)

0 commit comments

Comments
 (0)