-
Notifications
You must be signed in to change notification settings - Fork 1
[WIP] Fix KeyError in import_traces method for missing fields #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,184 @@ | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| Demonstration of the import_traces() function. | ||||||||||||||||||||
|
|
||||||||||||||||||||
| This script shows how to use the import_traces() function with various scenarios. | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| import json | ||||||||||||||||||||
| import tempfile | ||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| # The import_traces function (from project-book.ipynb) | ||||||||||||||||||||
| def import_traces(json_file_path): | ||||||||||||||||||||
|
Comment on lines
+9
to
+12
|
||||||||||||||||||||
| # The import_traces function (from project-book.ipynb) | |
| def import_traces(json_file_path): | |
| from typing import List, Dict, Any | |
| # The import_traces function (from project-book.ipynb) | |
| def import_traces(json_file_path: str) -> List[Dict[str, Any]]: |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition if trace.keys() will always evaluate to True because dict.keys() returns a dict_keys view object which is always truthy, even for an empty dict. This means the 'none' fallback will never be shown. The condition should be if trace or if len(trace) > 0 to properly check if the dictionary has any keys.
| f"Available fields: {', '.join(trace.keys()) if trace.keys() else 'none'}. " | |
| f"Available fields: {', '.join(trace.keys()) if trace else 'none'}. " |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment to 'traces' is unnecessary as it is redefined before this value is used.
| traces = import_traces("nonexistent_file.json") | |
| import_traces("nonexistent_file.json") |
Copilot
AI
Jan 18, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable traces is not used.
| traces = import_traces(str(malformed_file)) | |
| import_traces(str(malformed_file)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function signature is missing type hints that are present in the other implementations. The parameter should be annotated as
json_file_path: strand the return type should be-> List[Dict[str, Any]]for consistency with the implementations in tests/test_import_traces.py and tests/test_import_traces_simple.py.