Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add .mutate() method to builder DSL for row-wise transformations#950

Merged
SkBlaz merged 5 commits intomasterSkBlaz/py3plex:masterfrom
copilot/add-builder-dsl-supportSkBlaz/py3plex:copilot/add-builder-dsl-supportCopy head branch name to clipboard
Dec 25, 2025
Merged

Add .mutate() method to builder DSL for row-wise transformations#950
SkBlaz merged 5 commits intomasterSkBlaz/py3plex:masterfrom
copilot/add-builder-dsl-supportSkBlaz/py3plex:copilot/add-builder-dsl-supportCopy head branch name to clipboard

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 25, 2025

The builder DSL was missing support for row-wise column transformations (mutations). Only aggregation operations like .summarize() and .aggregate() were available for creating derived columns.

Changes

Core implementation:

  • Added mutate_specs field to SelectStmt AST node
  • Implemented .mutate(**transformations) method on QueryBuilder
  • Added _apply_mutate() executor function for row-wise transformation logic
  • Updated post-processing pipeline to trigger when mutations are present

Mutation support:

  • Lambda functions with access to all row attributes
  • Constant values
  • String expressions referencing other columns

Documentation:

  • Added comprehensive RST documentation in docfiles/user_guide/dsl.rst with "MUTATE - Row-wise Transformations" section
  • Added reference documentation in docfiles/reference/dsl_reference.rst
  • Updated query builder method lists to include .mutate() in chainable operations
  • Created examples/network_analysis/example_dsl_mutate.py with 6 comprehensive examples
  • Updated examples/network_analysis/README.md with DSL section listing all examples
  • Added mutate operator to flagship example in main README.md - demonstrates creating derived influence scores in a production-quality workflow

Example

from py3plex.dsl import Q

# Create derived columns using lambda transformations
result = Q.nodes().compute("degree", "clustering").mutate(
    hub_score=lambda row: row.get("degree", 0) * row.get("clustering", 0),
    is_hub=lambda row: row.get("degree", 0) > 2,
    normalized=lambda row: row.get("degree", 0) / 10.0
).execute(network)

# Chain with other DSL operations
result = (
    Q.nodes()
    .where(layer="social")
    .compute("degree", "betweenness_centrality")
    .mutate(
        influence=lambda row: (
            row.get("degree", 0) * 0.4 + 
            row.get("betweenness_centrality", 0) * 0.6
        )
    )
    .execute(network)
)

The five core DSL operations (node/edge selection, filtering, mutations, summary) are now all supported and documented.

Original prompt

This section details on the original issue you should resolve

<issue_title>builder dsl</issue_title>
<issue_description>make sure builder dsl supports key ops such as

  1. node selection
  2. edge selection
  3. filtering
  4. mutations
  5. summary

no mew md allowed.</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 December 25, 2025 19:02
Co-authored-by: SkBlaz <10035780+SkBlaz@users.noreply.github.com>
Co-authored-by: SkBlaz <10035780+SkBlaz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for key ops in builder DSL Add .mutate() method to builder DSL for row-wise transformations Dec 25, 2025
Copilot AI requested a review from SkBlaz December 25, 2025 19:07
@SkBlaz
Copy link
Copy Markdown
Owner

SkBlaz commented Dec 25, 2025

@copilot make sure they are in rst docs and under examples folder in relevant places

Co-authored-by: SkBlaz <10035780+SkBlaz@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 25, 2025

@copilot make sure they are in rst docs and under examples folder in relevant places

Added comprehensive documentation for the mutate operation:

RST Documentation:

  • docfiles/user_guide/dsl.rst - "MUTATE - Row-wise Transformations" section with examples
  • docfiles/reference/dsl_reference.rst - "Row-wise Transformations (Mutate)" reference section

Examples:

  • examples/network_analysis/example_dsl_mutate.py - Already in place with 6 comprehensive examples
  • examples/network_analysis/README.md - Added DSL section listing all examples including mutate

Commit: cccb7df

@SkBlaz
Copy link
Copy Markdown
Owner

SkBlaz commented Dec 25, 2025

@copilot add it to the flagship example in readme (mutate operator)

Co-authored-by: SkBlaz <10035780+SkBlaz@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 25, 2025

@copilot add it to the flagship example in readme (mutate operator)

Added mutate operator to the flagship example in README.md. The example now demonstrates creating a derived influence_score that combines degree and betweenness centrality metrics using the mutate operation.

Commit: 7ea980e

@SkBlaz SkBlaz marked this pull request as ready for review December 25, 2025 23:49
@SkBlaz SkBlaz merged commit 0183fd9 into master Dec 25, 2025
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.

builder dsl

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.