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

Documentation improvements #123

Merged
merged 2 commits into from
Mar 23, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,4 @@ If you do not wish to participate, one can opt-out with one of the following met
- Shreya Datar (@datarshreya)
- Baldo Faieta (@baldofaieta)
- Anwar Brini (@AnwarBrini)
- Gourav Kumar (@gms101)
2 changes: 1 addition & 1 deletion docs/reference/api-reference/decorators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Actual decorators:
.. autoclass:: hamilton.function_modifiers.subdag
:special-members: __init__

@parameterize_subdag
@parameterized_subdag
------------------------
.. autoclass:: hamilton.function_modifiers.parameterized_subdag
:special-members: __init__
Expand Down
12 changes: 6 additions & 6 deletions hamilton/function_modifiers/delayed.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ class resolve(DynamicResolver):
This is particularly useful when you don't know how you want your functions to resolve until
configuration time. Say, for example, we want to add two series, and we need to pass the set of
series to add as a configuration parameter, as we'll be changing it regularly. Without this,
you would have to have them as part of the the same dataframe. E.G.
you would have to have them as part of the same dataframe. E.G.

.. code-block:: python

@parameterize(
@parameterize_values(
series_sum_1={"s1": "series_1", "s2": "series_2"},
series_sum_2={"s1": "series_3", "s2": "series_4"},
)
def summation(df: pd.DataFrame, s1: str, s2: str) -> pd.Series:
return sum(df[item] for item in series_to_sum)
return df[s1] + df[s2]

Note that there are a lot of benefits to this code, but it is a workaround for the fact that
we cannot configure the dependencies. With the `@resolve` decorator, we can actually dynamically
Expand All @@ -77,13 +77,13 @@ def summation(df: pd.DataFrame, s1: str, s2: str) -> pd.Series:

@resolve(
when=ResolveAt.CONFIG_AVAILABLE
decorate_with=lambda first_series_sum, second_series_sum: parameterize(
decorate_with=lambda first_series_sum, second_series_sum: parameterize_sources(
series_sum_1={"s1": first_series_sum[0], "s2": second_series_sum[1]},
series_sum_2={"s1": second_series_sum[1], "s2": second_series_sum[2]},

)
def summation(first_series: pd.Series, second_series: pd.Series) -> pd.Series:
return first_series + second_series
def summation(s1: pd.Series, s2: pd.Series) -> pd.Series:
return s1 + s2

Note how this works:
1. The `decorate_with` argument is a function that gives you the decorator you want to apply.
Expand Down
4 changes: 2 additions & 2 deletions hamilton/function_modifiers/recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class parameterized_subdag(base.NodeCreator):

.. code-block:: python

@parameterize_subdag(
@parameterized_subdag(
feature_modules,
parameterization={
"from_datasource_1" : {"inputs" : {"data" : value("datasource_1.csv"}},
Expand All @@ -420,7 +420,7 @@ def feature_engineering(feature_df: pd.DataFrame) -> pd.DataFrame:

.. code-block:: python

@parameterize_subdag(
@parameterized_subdag(
feature_modules,
inputs={"data" : value("datasource_1.csv")},
from_datasource_1={},
Expand Down
2 changes: 1 addition & 1 deletion tests/function_modifiers/test_recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def test_reuse_subdag_end_to_end():
assert res["sum_everything"] == 318


def test_parameterize_subdag():
def test_parameterized_subdag():
def bar(input_1: int) -> int:
return input_1 + 1

Expand Down