Skip to content

Commit 0c7274e

Browse files
committed
Add input hydration and output materialization configs to custom dataframes.
Summary: This revision adds input hydration and output materialization configs to custom dataframes. It also adds a sanity test to make sure everything is hooked in right. Github Issue: #2027 Test Plan: unit Reviewers: schrockn Reviewed By: schrockn Differential Revision: https://dagster.phacility.com/D2032
1 parent 6c24bd0 commit 0c7274e

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

python_modules/libraries/dagster-pandas/dagster_pandas/data_frame.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,13 @@ def _dagster_type_check(_, value):
178178
else None,
179179
)
180180

181-
# add input_hydration_confign and output_materialization_config
182-
# https://github.com/dagster-io/dagster/issues/2027
183-
return DagsterType(name=name, type_check_fn=_dagster_type_check, description=description)
181+
return DagsterType(
182+
name=name,
183+
type_check_fn=_dagster_type_check,
184+
input_hydration_config=dataframe_input_schema,
185+
output_materialization_config=dataframe_output_schema,
186+
description=description,
187+
)
184188

185189

186190
def _execute_summary_stats(type_name, value, event_metadata_fn):

python_modules/libraries/dagster-pandas/dagster_pandas_tests/test_data_frame.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66
)
77
from dagster_pandas.data_frame import _execute_summary_stats, create_dagster_pandas_dataframe_type
88
from dagster_pandas.validation import PandasColumn
9-
from pandas import DataFrame
9+
from pandas import DataFrame, read_csv
1010

1111
from dagster import (
1212
DagsterInvariantViolationError,
1313
DagsterType,
1414
EventMetadataEntry,
15+
InputDefinition,
1516
Output,
1617
OutputDefinition,
1718
check_dagster_type,
1819
execute_pipeline,
20+
execute_solid,
1921
pipeline,
2022
solid,
2123
)
24+
from dagster.utils import safe_tempfile_path
2225

2326

2427
def test_create_pandas_dataframe_dagster_type():
@@ -153,3 +156,36 @@ def test_execute_summary_stats_error():
153156
DataFrame({}),
154157
lambda value: [EventMetadataEntry.text('baz', 'qux', 'quux'), 'rofl'],
155158
)
159+
160+
161+
def test_custom_dagster_dataframe_hydration_ok():
162+
input_dataframe = DataFrame({'foo': [1, 2, 3]})
163+
with safe_tempfile_path() as input_csv_fp, safe_tempfile_path() as output_csv_fp:
164+
input_dataframe.to_csv(input_csv_fp)
165+
TestDataFrame = create_dagster_pandas_dataframe_type(
166+
name='TestDataFrame', columns=[PandasColumn.exists('foo'),]
167+
)
168+
169+
@solid(
170+
input_defs=[InputDefinition('test_df', TestDataFrame)],
171+
output_defs=[OutputDefinition(TestDataFrame)],
172+
)
173+
def use_test_dataframe(_, test_df):
174+
test_df['bar'] = [2, 4, 6]
175+
return test_df
176+
177+
solid_result = execute_solid(
178+
use_test_dataframe,
179+
environment_dict={
180+
'solids': {
181+
'use_test_dataframe': {
182+
'inputs': {'test_df': {'csv': {'path': input_csv_fp}}},
183+
'outputs': [{'result': {'csv': {'path': output_csv_fp}}},],
184+
}
185+
}
186+
},
187+
)
188+
189+
assert solid_result.success
190+
solid_output_df = read_csv(output_csv_fp)
191+
assert all(solid_output_df['bar'] == [2, 4, 6])

0 commit comments

Comments
 (0)