Skip to content

Merge dplyr-style chainable API into DSL v2 builder#998

Merged
SkBlaz merged 3 commits intomasterfrom
copilot/merge-dplyr-style-api
Jan 6, 2026
Merged

Merge dplyr-style chainable API into DSL v2 builder#998
SkBlaz merged 3 commits intomasterfrom
copilot/merge-dplyr-style-api

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 6, 2026

The library had two separate APIs for chainable operations: graph_ops.py (dplyr-style) and dsl/builder.py (query builder), forcing users to learn and switch between both. This consolidates them into a unified interface.

Changes

DSL Builder (py3plex/dsl/builder.py)

  • Added 11 dplyr-style methods to QueryBuilder: filter(), filter_expr(), head(), tail(), take(), sample(), slice(), first(), last(), pluck(), collect()
  • filter() aliases existing where() for traditional dplyr naming
  • filter_expr() enables string-based filtering with safe AST evaluation
  • Sampling and slicing methods provide pandas-like data manipulation

Executor (py3plex/dsl/executor.py)

  • Extended _apply_post_filters() to handle new filter types (expression, tail, sample, slice, last)
  • Added _safe_eval_expr() for secure expression evaluation using AST validation
  • Filters applied pre-compute for efficiency where possible

Documentation

  • Updated AGENTS.md to document unified API
  • Enhanced example_dsl_dplyr_operations.py with demonstration of new methods
  • Added comprehensive test suite (tests/test_dplyr_integration.py)

Example

from py3plex.dsl import Q, L

# Before: separate APIs
from py3plex.graph_ops import nodes
df = nodes(net).filter(lambda n: n["degree"] > 5).to_pandas()

# After: unified builder API
df = (
    Q.nodes()
     .compute("degree")
     .filter(degree__gt=5)           # dplyr-style filter
     .filter_expr("layer == 'ppi'")  # string-based filtering  
     .arrange("-degree")
     .head(10)
     .sample(5, seed=42)
     .execute(net)
     .to_pandas()
)

Backward Compatibility: Standalone graph_ops module remains available. No breaking changes to existing DSL v2 functionality.

Original prompt

This section details on the original issue you should resolve

<issue_title>dplyr in dsl2</issue_title>
<issue_description>merge dplyr style chainable api into dslV2 (builder), to reduce cognitive load and simplify. no new md allowed, make sure tests pass//functionality is preserved. Update all docs/examples where relevant</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 6, 2026 01:55
- Integrated filter(), filter_expr(), head(), tail(), sample(), slice(), first(), last(), take(), pluck(), collect() methods
- Updated executor to support new post-filter types (expression, tail, sample, slice, last)
- Added safe expression evaluator for filter_expr()
- Updated AGENTS.md documentation with merged API section
- Updated example_dsl_dplyr_operations.py to demonstrate new methods
- All methods tested and working correctly

Co-authored-by: SkBlaz <10035780+SkBlaz@users.noreply.github.com>
- Created test_dplyr_integration.py with 12 tests covering all new methods
- All tests pass successfully
- Tests verify filter(), filter_expr(), head(), tail(), take(), sample(), slice(), first(), last(), pluck(), collect() and method chaining

Co-authored-by: SkBlaz <10035780+SkBlaz@users.noreply.github.com>
Copilot AI changed the title [WIP] Merge dplyr style chainable API into dslV2 Merge dplyr-style chainable API into DSL v2 builder Jan 6, 2026
Copilot AI requested a review from SkBlaz January 6, 2026 02:02
@SkBlaz SkBlaz marked this pull request as ready for review January 6, 2026 02:24
@SkBlaz SkBlaz merged commit bc2862a into master Jan 6, 2026
31 checks 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.

dplyr in dsl2

2 participants