Seth Stokes
11/21/2024, 9:03 PMCollect should any of these _filter* step 's return an empty DataFrame?
I know Collect executes as async so iteration may be the wrong terminology,
but I'd like the downstream nodes of the empty result to not have to try to do anything with that empty DataFrame
to produce the requested node. If its empty then don't fail the other tasks.
@extract_fields({
"child_process_run_id": int,
"child_process_completed_at": pd.Timestamp,
})
@pipe_input(
step(_filter_run_bom).when(last_run="bom"),
step(_filter_run_latest).when(last_run="last"),
step(_filter_run_date, completion_date=source("completion_date")).when(last_run="completion_date"),
)
def child_process_run_info(child_process_runs: pd.DataFrame) -> Dict[int, pd.Timestamp]:Elijah Ben Izzy
11/21/2024, 9:06 PMSeth Stokes
11/21/2024, 9:06 PMElijah Ben Izzy
11/21/2024, 9:07 PMSeth Stokes
11/21/2024, 9:10 PMclass NoRunsFoundError(Exception):
...
@extract_fields({
"child_process_run_id": int,
"child_process_completed_at": pd.Timestamp,
})
@pipe_input(
step(_filter_run_bom).when(last_run="bom"),
step(_filter_run_latest).when(last_run="last"),
step(_filter_run_date, completion_date=source("completion_date")).when(last_run="completion_date"),
)
def child_process_run_info(
child_process_runs: pd.DataFrame,
child_rec_process_code: str,
completion_date: Optional[str]
) -> Dict[int, pd.Timestamp]:
"""Return run id for process from `last_run` logic."""
try:
info = {
"child_process_run_id": child_process_runs["id"].iloc[0],
"child_process_completed_at": pd.to_datetime(child_process_runs["completed_at"].iloc[0]),
}
return info
except Exception as e:
raise NoRunsFoundError(f"No data for process {child_rec_process_code} on date {completion_date}") from eSeth Stokes
11/21/2024, 9:10 PMGracefulErrorAdapter?Elijah Ben Izzy
11/21/2024, 9:10 PMElijah Ben Izzy
11/21/2024, 9:11 PMElijah Ben Izzy
11/21/2024, 9:12 PMNone ) from the parallel block. Haven’t run it in a bit but it should be doable (report back)?Seth Stokes
11/21/2024, 9:12 PMElijah Ben Izzy
11/21/2024, 9:12 PMSeth Stokes
11/21/2024, 9:20 PMline 140, in download_run_results__default
for endpoint, completed_at in all_last_run_result_inputs:
^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot unpack non-iterable NoneType objectElijah Ben Izzy
11/21/2024, 9:20 PMNone. Should be simple enough to iterate through then onlyunpack if it’s not NoneElijah Ben Izzy
11/21/2024, 9:21 PMfor item in all_last_run_result_inputs:
if item is None:
continue
endpoint, completed_at = item
...Seth Stokes
11/21/2024, 9:21 PMfor endpoint, completed_at in filter(None,all_last_run_result_inputs):
This should do it no?Elijah Ben Izzy
11/21/2024, 9:22 PMfilter could take in None, but turns out it can…)Seth Stokes
11/21/2024, 9:24 PMGracefulErrorAdapterElijah Ben Izzy
11/21/2024, 9:25 PMSeth Stokes
11/21/2024, 10:43 PM@pipe_input(
step(_filter_out_noise).when_in(cond=["a", "b"]),
step(_filter_out_more_stuff).when_in(cond=["a", "b"]),
step(_filter_out_noise).when_in(cond=["c", "d"]),
)
def clean_data(raw_data: pd.DataFrame) -> pd.DataFrame:
return raw_data
Essentially, the above probably work, but I am checking to see if group could work here?
@pipe_input(
group(step(_filter_out_noise), step(_filter_out_more_stuff)).when_in(cond=["a", "b"]),
step(_filter_out_noise).when_in(cond=["c", "d"]),
)
def clean_data(raw_data: pd.DataFrame) -> pd.DataFrame:
return raw_data
And of course, the classic config.when_in would work too.Elijah Ben Izzy
11/21/2024, 10:54 PMSeth Stokes
11/21/2024, 10:55 PMstep().when_in() api that enables multiple scenarios on the same node.Seth Stokes
11/21/2024, 10:56 PMElijah Ben Izzy
11/21/2024, 10:57 PMwhen_in should work — I see, you want them as the same criteriaElijah Ben Izzy
11/21/2024, 10:57 PMSeth Stokes
11/21/2024, 11:00 PMstep(lambda _df: _df.pipe(_filter_out_noise).pipe(_filter_out_netted_updowns)).when_in(cond=["a", "b"])Elijah Ben Izzy
11/21/2024, 11:02 PMJernj Frank
11/21/2024, 11:02 PMpipe_input and setting the global when_in for each?Jernj Frank
11/21/2024, 11:03 PMgroup would look likeElijah Ben Izzy
11/21/2024, 11:03 PMwhen_in look like? Oh, I see, decorating with @config.when_in?Jernj Frank
11/21/2024, 11:06 PMJernj Frank
11/21/2024, 11:07 PMElijah Ben Izzy
11/21/2024, 11:09 PMJernj Frank
11/21/2024, 11:16 PMSeth Stokes
11/22/2024, 7:21 PMupstream_int come from?
@pipe_input(
step(_add_one)
step(_add_two, y=source("upstream_node")),
on_input = "p2"
)
def final_result(p1: int, p2: int, p3: int) -> int:
return upstream_intElijah Ben Izzy
11/22/2024, 7:22 PMElijah Ben Izzy
11/22/2024, 7:22 PMp1 + p2 + p3 or something like that. If you want to fix that would be appreciated 🙂Seth Stokes
11/22/2024, 7:38 PMnamed and on_input when I stumbled across that.
I think we already proposed 2 good ways so I'm happy.
How can I go about amending? When I hit the edit from the Hamilton Docs page, it sends me to the rst in github