-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds FunctionInputOutputTypeChecker #757
Conversation
This is a lifecycle adapter that one can add to strictly enforce the types of things at runtime. It will check the input to and the output from a function and check that it matches the expected type annotation. It modifies/fixes the pandas split-apply-combine example to conform to the expected types; it actually found mismatches between what was typed and what was passed in. I had to modify graph_functions.py so that the error message from the pre-node-execute hook would show up in the right place and the post-node-execute hook would not run. Note: this does not do anything smart with Pandera or Annotated types just yet, but it could in future. Test generated with the help of co-pilot. A little ugly, but they do the job.
They changed what was output, so test needed to be fixed.
c9b78f4
to
0915e8d
Compare
result=result, | ||
task_id=task_id, | ||
) | ||
if not pre_node_execute_errored and adapter.does_hook( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm we should really have a context manager that does this... But this works for now.
@@ -206,6 +208,7 @@ def pre_node_execute( | |||
node_return_type=node_.type, | |||
task_id=task_id, | |||
run_id=run_id, | |||
node_input_types={k: v[0] for k, v in node_.input_types.items()}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add TODO for integrating the HamiltonNode
class
hamilton/lifecycle/default.py
Outdated
import time | ||
from typing import Any, Callable, Dict, List, Optional, Union | ||
|
||
if sys.version_info >= (3, 9): | ||
from typing import Literal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think literal is 3.8+
?
To centralize this and make it clear we have two ways of checking types. I don't want to merge them because the input type checker is less strict. It doesn't recursively go check the values of inputs. So there's a TODO: to figure out what to do, and how to unify. In the meantime they're in the same file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, looks good when you make the changes
Also adds more to example
This is a lifecycle adapter that one can add to strictly enforce the types of things at runtime. It will check the input to and the output from a function and check that it matches the expected type annotation.
It modifies/fixes the pandas split-apply-combine example to conform to the expected types; it actually found mismatches between what was typed and what was passed in.
I had to modify graph_functions.py so that the error message from the pre-node-execute hook would show up in the right place and the post-node-execute hook would not run.
Note: this does not do anything smart with Pandera or Annotated types just yet, but it could in future.
Test generated with the help of co-pilot. A little ugly, but they do the job.
Changes
How I tested this
Notes
Checklist