pyiron / pyiron_workflow

Graph-and-node based workflows
BSD 3-Clause "New" or "Revised" License
10 stars 1 forks source link

[patch] Dataclass transformer #308

Closed liamhuber closed 1 month ago

liamhuber commented 1 month ago

Introduce a node for converting inputs to a dataclass instance. Contributes to #268.

TODO:

Demo:

from dataclasses import dataclass, field

from pyiron_workflow import Workflow

def some_list():
    return [1, 2, 3]

@Workflow.wrap.as_dataclass_node
@dataclass
class Foo:
    necessary: str
    bar: str = "bar"
    answer: int = 42
    complex_: list = field(default_factory=some_list)

f = Foo()
print(f.readiness_report)
>>> InputsToDataclassFoo readiness: False
... STATE:
... running: False
... failed: False
... INPUTS:
... necessary ready: False
... bar ready: True
... answer ready: True
... complex_ ready: True

f(necessary="input as a node kwarg")
>>> Foo(necessary='input as a node kwarg', bar='bar', answer=42, complex_=[1, 2, 3])

EDIT: decorator name

github-actions[bot] commented 1 month ago

Binder :point_left: Launch a binder notebook on branch _pyiron/pyiron_workflow/dataclasstransformer

codacy-production[bot] commented 1 month ago

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
:white_check_mark: +0.16% (target: -1.00%) :white_check_mark: 95.12%
Coverage variation details | | Coverable lines | Covered lines | Coverage | | ------------- | ------------- | ------------- | ------------- | | Common ancestor commit (efbf51428b39a819047f8e19592f33044e28276b) | 3761 | 3340 | 88.81% | | | Head commit (06634aae51f7c38687a0b14f00134e102b99a2e2) | 3797 (+36) | 3378 (+38) | 88.96% (**+0.16%**) | **Coverage variation** is the difference between the coverage for the head and common ancestor commits of the pull request branch: ` - `
Diff coverage details | | Coverable lines | Covered lines | Diff coverage | | ------------- | ------------- | ------------- | ------------- | | Pull request (#308) | 41 | 39 | **95.12%** | **Diff coverage** is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: `/ * 100%`

See your quality gate settings    Change summary preferences

Codacy will stop sending the deprecated coverage status from June 5th, 2024. Learn more

coveralls commented 1 month ago

Pull Request Test Coverage Report for Build 8976830583

Details


Files with Coverage Reduction New Missed Lines %
transform.py 3 98.13%
create.py 7 93.33%
<!-- Total: 10 -->
Totals Coverage Status
Change from base Build 8976792554: 0.2%
Covered Lines: 3378
Relevant Lines: 3797

💛 - Coveralls