-
Notifications
You must be signed in to change notification settings - Fork 0
Improve Table ergonomics
#6
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
Conversation
- Expand .gitignore with comprehensive rules
- Add enhanced dict access for Table class - Update tests to use new access pattern
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.
cubic analysis
1 issue found across 4 files • Review in cubic
React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.
chidian/table.py
Outdated
| ["John", "Jane", "Bob"] | ||
| """ | ||
| # Check if this is a path expression (contains dot) | ||
| if "." in key: |
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.
Calling super().getitem for keys that do not contain a dot breaks the documented behaviour of allowing column access through table["column"]. When the key is a plain column name (e.g. "name") it should delegate to get(), not to the parent dict, otherwise a KeyError will be raised unless a row happens to share that key. The condition should also treat any key that is not a row identifier (doesn't start with "$") as a path expression.
Prompt for AI agents
Address the following comment on chidian/table.py at line 759:
<comment>Calling super().__getitem__ for keys that do not contain a dot breaks the documented behaviour of allowing column access through table["column"]. When the key is a plain column name (e.g. "name") it should delegate to get(), not to the parent dict, otherwise a KeyError will be raised unless a row happens to share that key. The condition should also treat any key that is not a row identifier (doesn't start with "$") as a path expression.</comment>
<file context>
@@ -335,6 +335,434 @@ def group_by(self, path: str) -> dict[Any, "Table"]:
return {key: Table(rows) for key, rows in groups.items()}
+ def extract(self, path: str) -> "Table":
+ """
+ Extract values from all rows using a path and return as a new Table.
+
+ This method is particularly useful for extracting nested structures
+ like FHIR Bundle entries or other collections within your data.
</file context>
| if "." in key: | |
| if "." in key or not key.startswith("$"): |
- Refactor Table class to remove dict inheritance - Improve row key management - Modify test cases for new implementation - Bump package version to 0.1.2
Closes N/A
Background
The
Tableclass is a sparse table (a list of dictionaries with some helper wrappers). Used more DSL-like features to make it neaterDesign (high-level)
get,__getitem__, etc.joinhelper function that is SQL-like and just does left & inner joinsOther notes
Summary by cubic
Added new Table methods for extracting data, joining tables, and dot notation access, making data manipulation easier and more flexible.