Skip to content

Commit

Permalink
fix: output csv writing should work even if not all documents have al…
Browse files Browse the repository at this point in the history
…l keys (#252)

* chore: ui nits

* chore: ui nits

* feat: add tutorial for the supreme court hearings

* fix: output csv writing should work even if not all documents have all the keys
  • Loading branch information
shreyashankar authored Dec 26, 2024
1 parent 329d47f commit a377c20
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docetl/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ def save(self, data: List[Dict]):

with open(output_config["path"], "w", newline="") as file:
writer = csv.DictWriter(file, fieldnames=data[0].keys())
limited_data = [{k: d.get(k, None) for k in data[0].keys()} for d in data]
writer.writeheader()
writer.writerows(data)
writer.writerows(limited_data)
self.console.print(
f"[green italic]💾 Output saved to {output_config['path']}[/green italic]"
)
Expand Down

0 comments on commit a377c20

Please sign in to comment.