Skip to content

Conversation

@ericpan64
Copy link
Owner

@ericpan64 ericpan64 commented Aug 14, 2025

Closes N/A

Background

The Table class is a sparse table (a list of dictionaries with some helper wrappers). Used more DSL-like features to make it neater

Design (high-level)

  • Use dot syntax for get, __getitem__, etc.
  • A join helper function that is SQL-like and just does left & inner joins

Other notes


Summary by cubic

Added new Table methods for extracting data, joining tables, and dot notation access, making data manipulation easier and more flexible.

  • New Features
  • Added extract and from_path methods for pulling nested and structured data.
  • Implemented join for merging tables with flexible key options and join types.
  • Enabled dot notation access for rows (e.g., table["$0.name"]) and columns.
  • Updated tests to use new access pattern.

- Expand .gitignore with comprehensive rules
- Add enhanced dict access for Table class
- Update tests to use new access pattern
@ericpan64 ericpan64 changed the title Epan/table ergonomics Improve Table ergonomics Aug 14, 2025
Copy link

@cubic-dev-ai cubic-dev-ai bot left a 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:
Copy link

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[&quot;column&quot;]. When the key is a plain column name (e.g. &quot;name&quot;) 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&#39;t start with &quot;$&quot;) as a path expression.</comment>

<file context>
@@ -335,6 +335,434 @@ def group_by(self, path: str) -&gt; dict[Any, &quot;Table&quot;]:
 
         return {key: Table(rows) for key, rows in groups.items()}
 
+    def extract(self, path: str) -&gt; &quot;Table&quot;:
+        &quot;&quot;&quot;
+        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>
Suggested change
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
@ericpan64 ericpan64 merged commit d078da7 into main Aug 14, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants