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

Updates first dataflow docs #1245

Merged
merged 1 commit into from
Dec 2, 2024
Merged
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
24 changes: 18 additions & 6 deletions docs/get-started/your-first-dataflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ To actually run the dataflow, we'll need to write :doc:`a driver <../concepts/dr

import pandas as pd

# We add this to speed up running things if you have a lot in your python environment.
from hamilton import registry; registry.disable_autoload()
from hamilton import driver, base
import my_functions # we import the module here!
from hamilton import driver


logger = logging.getLogger(__name__)
logging.basicConfig(stream=sys.stdout)
Expand All @@ -86,10 +89,14 @@ To actually run the dataflow, we'll need to write :doc:`a driver <../concepts/dr
'signups': pd.Series([1, 10, 50, 100, 200, 400], index=index),
'spend': pd.Series([10, 10, 20, 40, 40, 50], index=index),
}
# we need to tell hamilton where to load function definitions from
config = {} # we don't have any configuration or invariant data for this example.
dr = driver.Driver(config, my_functions) # can pass in multiple modules
# we need to specify what we want in the final dataframe.
dr = (
driver.Builder()
.with_config({}) # we don't have any configuration or invariant data for this example.
.with_modules(my_functions) # we need to tell hamilton where to load function definitions from
.with_adapters(base.PandasDataFrameResult()) # we want a pandas dataframe as output
.build()
)
# we need to specify what we want in the final dataframe (these could be function pointers).
output_columns = [
'spend',
'signups',
Expand All @@ -99,7 +106,7 @@ To actually run the dataflow, we'll need to write :doc:`a driver <../concepts/dr
# let's create the dataframe!
df = dr.execute(output_columns, inputs=initial_columns)
# `pip install sf-hamilton[visualization]` earlier you can also do
# dr.visualize_execution(output_columns,'./my_dag.dot', {})
# dr.visualize_execution(output_columns,'./my_dag.png', {})
print(df)

Run the script with the following command:
Expand All @@ -122,3 +129,8 @@ Not only is your spend to signup ratio decreasing exponentially (your product is
successfully run your first Hamilton Dataflow. Kudos!

See, wasn't that quick and easy?

Note: if you're ever like "why are things taking a while to execute?", then you might have too much
in your python environment and Hamilton is auto-loading all the extensions. You can disable this by
setting the environment variable ``HAMILTON_AUTOLOAD_EXTENSIONS=0`` or programmatically via
``from hamilton import registry; registry.disable_autoload()`` - for more see :doc:`../how-tos/extensions-autoloading`.