Ejemplo n.º 1
0
def _construct_enum_from_snap(config_type_snap):
    check.list_param(config_type_snap.enum_values, "enum_values", ConfigEnumValueSnap)

    return Enum(
        name=config_type_snap.key,
        enum_values=[
            EnumValue(enum_value_snap.value, description=enum_value_snap.description)
            for enum_value_snap in config_type_snap.enum_values
        ],
    )
Ejemplo n.º 2
0
def test_deserialize_solid_def_snaps_enum():
    @solid(
        config=Field(Enum('CowboyType', [EnumValue('good'), EnumValue('bad'), EnumValue('ugly')]))
    )
    def noop_solid(_):
        pass

    @pipeline
    def noop_pipeline():
        noop_solid()

    pipeline_snapshot = PipelineSnapshot.from_pipeline_def(noop_pipeline)
    solid_def_snap = pipeline_snapshot.get_solid_def_snap('noop_solid')
    recevied_config_type = pipeline_snapshot.get_config_type_from_solid_def_snap(solid_def_snap)
    assert isinstance(recevied_config_type, Enum)
    assert recevied_config_type.given_name == 'CowboyType'
    assert all(
        enum_value.config_value in ('good', 'bad', 'ugly')
        for enum_value in recevied_config_type.enum_values
    )
Ejemplo n.º 3
0
def test_deserialize_solid_def_snaps_enum():
    @solid(config_schema=Field(
        Enum("CowboyType",
             [EnumValue("good"),
              EnumValue("bad"),
              EnumValue("ugly")])))
    def noop_solid(_):
        pass

    @pipeline
    def noop_pipeline():
        noop_solid()

    pipeline_snapshot = PipelineSnapshot.from_pipeline_def(noop_pipeline)
    solid_def_snap = pipeline_snapshot.get_solid_def_snap("noop_solid")
    recevied_config_type = pipeline_snapshot.get_config_type_from_solid_def_snap(
        solid_def_snap)
    assert isinstance(recevied_config_type, Enum)
    assert recevied_config_type.given_name == "CowboyType"
    assert all(enum_value.config_value in ("good", "bad", "ugly")
               for enum_value in recevied_config_type.enum_values)
Ejemplo n.º 4
0
def test_deserialize_solid_def_snaps_multi_type_config(snapshot):
    @solid(config=Field(
        Permissive({
            'foo':
            Field(Array(float)),
            'bar':
            Selector({
                'baz': Field(Noneable(int)),
                'qux': {
                    'quux':
                    Field(str),
                    'corge':
                    Field(
                        Enum(
                            'RGB',
                            [
                                EnumValue('red'),
                                EnumValue('green'),
                                EnumValue('blue')
                            ],
                        )),
                },
            }),
        })))
    def fancy_solid(_):
        pass

    @pipeline
    def noop_pipeline():
        fancy_solid()

    pipeline_snapshot = PipelineSnapshot.from_pipeline_def(noop_pipeline)
    solid_def_snap = pipeline_snapshot.get_solid_def_snap('fancy_solid')
    recevied_config_type = pipeline_snapshot.get_config_type_from_solid_def_snap(
        solid_def_snap)
    snapshot.assert_match(
        serialize_pp(snap_from_config_type(recevied_config_type)))
    _map_has_stable_hashes(
        recevied_config_type,
        pipeline_snapshot.config_schema_snapshot.all_config_snaps_by_key)
Ejemplo n.º 5
0
def test_deserialize_solid_def_snaps_multi_type_config(snapshot):
    @solid(config_schema=Field(
        Permissive({
            "foo":
            Field(Array(float)),
            "bar":
            Selector({
                "baz": Field(Noneable(int)),
                "qux": {
                    "quux":
                    Field(str),
                    "corge":
                    Field(
                        Enum(
                            "RGB",
                            [
                                EnumValue("red"),
                                EnumValue("green"),
                                EnumValue("blue")
                            ],
                        )),
                },
            }),
        })))
    def fancy_solid(_):
        pass

    @pipeline
    def noop_pipeline():
        fancy_solid()

    pipeline_snapshot = PipelineSnapshot.from_pipeline_def(noop_pipeline)
    solid_def_snap = pipeline_snapshot.get_solid_def_snap("fancy_solid")
    recevied_config_type = pipeline_snapshot.get_config_type_from_solid_def_snap(
        solid_def_snap)
    snapshot.assert_match(
        serialize_pp(snap_from_config_type(recevied_config_type)))
    _map_has_stable_hashes(
        recevied_config_type,
        pipeline_snapshot.config_schema_snapshot.all_config_snaps_by_key)
Ejemplo n.º 6
0
import pandas as pd
from dagster import solid, Field
from dagster.config.config_type import Enum as ConfigEnum, EnumValue


@solid(config={
        "filtered_column": Field(
            ConfigEnum("FilteredColumn", [EnumValue("province"), EnumValue("city")]),
            is_required=True,
            description="The name of the column that should be filtered."
        )
    })
def filter_df(context, df: pd.DataFrame, value_to_filter_by: str):
    column_name = str(context.solid_config["filtered_column"])
    context.log.info(f"filtering the column {column_name}, keeping only entries whose value is {value_to_filter_by}.")
    return df[df[column_name] == value_to_filter_by]