Skip to content
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

Fixes documentation to include new decorators #112

Merged
merged 2 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions docs/how-tos/use-in-jupyter-notebook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,27 @@ Run in a Jupyter Notebook

It's natural to run Hamilton within a jupyter notebook. There are a few ways to go about this:

#. Store all your code in the jupyter notebook, iterating on the functions themselves as well as the driver \

1. Store all your code in the jupyter notebook, iterating on the functions themselves as well as the driver \
(see example below).
#. Store your code externally, and import it into the notebook. Utilize the driver to run the code, iteratively adding \

2. Store your code externally, and import it into the notebook. Utilize the driver to run the code, iteratively adding \
functions to the driver as you settle on transform logic.
#. Execute/manage your code externally, and use the notebook to visualize the DAG/interact with it.

3. Execute/manage your code externally, and use the notebook to visualize the DAG/interact with it.
How you do this is entirely up to you! We're likely going to add more first-class jupyter notebook support.

Note that you can set up automatic reloading of modules (useful for (2) and (3)) using the following code:

.. code-block:: python

%load_ext autoreload
%autoreload 1
%aimport my_functions


More explanation in the notebook example below.

The `Hello World <https://github.com/DAGWorks-Inc/hamilton/blob/main/examples/hello_world/my_notebook.ipynb>`__ \
example notebook shows you how you would approach (1), and it should be easy to extend to the other approaches.

Expand Down
12 changes: 11 additions & 1 deletion docs/reference/api-reference/decorators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ Actual decorators:
.. autoclass:: hamilton.experimental.decorators.parameterize_frame.parameterize_frame
:special-members: __init__

@inject
------------------------
.. autoclass:: hamilton.function_modifiers.inject
:special-members: __init__

@does
------------------------
.. autoclass:: hamilton.function_modifiers.does
Expand All @@ -83,7 +88,12 @@ Actual decorators:
.. autoclass:: hamilton.function_modifiers.subdag
:special-members: __init__

@delay_resolution
@parameterize_subdag
------------------------
.. autoclass:: hamilton.function_modifiers.parameterized_subdag
:special-members: __init__

@resolve
------------------------
.. autoclass:: hamilton.function_modifiers.resolve
:special-members: __init__
6 changes: 3 additions & 3 deletions hamilton/function_modifiers/expanders.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,7 @@ def validate(self, fn: Callable):


class inject(parameterize):
"""
@inject allows you to replace parameters with values passed in. You can think of
"""@inject allows you to replace parameters with values passed in. You can think of
it as a `@parameterize` call that has only one parameterization, the result of which
is the name of the function. See the following examples:

Expand All @@ -958,6 +957,7 @@ def a_plus_10_plus_b_plus_2(nums: List[int]) -> int:
})
def sum_numbers(nums: List[int]) -> int:
return sum(nums)

Something to note -- we currently do not support the case in which the same parameter is utilized
multiple times as an injection. E.G. two lists, a list and a dict, two sources, etc...

Expand All @@ -968,6 +968,6 @@ def __init__(self, **key_mapping: ParametrizedDependency):
"""Instantiates an @inject decorator with the given key_mapping.

:param key_mapping: A dictionary of string to dependency spec.
This is the same as the input mapping in `@parameterize`.
This is the same as the input mapping in `@parameterize`.
"""
super(inject, self).__init__(**{parameterize.PLACEHOLDER_PARAM_NAME: key_mapping})
2 changes: 1 addition & 1 deletion hamilton/function_modifiers/recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def __init__(

Furthermore, note the following:

1. The parameterizations passed to the constructor are **kwargs, so you are not
1. The parameterizations passed to the constructor are \*\*kwargs, so you are not
allowed to name these `load_from`, `inputs`, or `config`. That's a good thing, as these
are not good names for variables anyway.

Expand Down