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

deprecate prefect tasks #483

Merged
merged 4 commits into from
Sep 6, 2024
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
65 changes: 51 additions & 14 deletions notebooks/integrations/integration-prefect-workflows.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"\n",
"### Setting up a simple flow\n",
"\n",
"Now we can get started! Creating Prefect **tasks** is easy enough on its own, but we've added\n",
"some simple ones to the ``rubicon_ml`` library."
"Now we can get started! Let's create some simple Prefect **tasks** for the core ``rubcion_ml`` loggers."
]
},
{
Expand All @@ -39,15 +38,56 @@
"metadata": {},
"outputs": [],
"source": [
"from rubicon_ml.workflow.prefect import (\n",
" get_or_create_project_task,\n",
" create_experiment_task,\n",
" log_artifact_task,\n",
" log_dataframe_task,\n",
" log_feature_task,\n",
" log_metric_task,\n",
" log_parameter_task,\n",
")"
"\n",
"from prefect import task\n",
"\n",
"\n",
"@task\n",
"def get_or_create_project_task(\n",
" persistence, root_dir, project_name, auto_git_enabled=False, storage_options={}, **kwargs\n",
"):\n",
" from rubicon_ml import Rubicon\n",
"\n",
"\n",
" rubicon = Rubicon(\n",
" persistence=persistence,\n",
" root_dir=root_dir,\n",
" auto_git_enabled=auto_git_enabled,\n",
" **storage_options,\n",
" )\n",
" project = rubicon.get_or_create_project(project_name, **kwargs)\n",
"\n",
" return project\n",
"\n",
"\n",
"@task\n",
"def create_experiment_task(project, **kwargs):\n",
" return project.log_experiment(**kwargs)\n",
"\n",
"\n",
"@task\n",
"def log_artifact_task(parent, **kwargs):\n",
" return parent.log_artifact(**kwargs)\n",
"\n",
"\n",
"@task\n",
"def log_dataframe_task(parent, df, **kwargs):\n",
" return parent.log_dataframe(df, **kwargs)\n",
"\n",
"\n",
"@task\n",
"def log_feature_task(experiment, feature_name, **kwargs):\n",
" return experiment.log_feature(feature_name, **kwargs)\n",
"\n",
"\n",
"@task\n",
"def log_metric_task(experiment, metric_name, metric_value, **kwargs):\n",
" return experiment.log_metric(metric_name, metric_value, **kwargs)\n",
"\n",
"\n",
"@task\n",
"def log_parameter_task(experiment, parameter_name, parameter_value, **kwargs):\n",
" return experiment.log_parameter(parameter_name, parameter_value, **kwargs)"
]
},
{
Expand All @@ -65,9 +105,6 @@
"metadata": {},
"outputs": [],
"source": [
"from prefect import task\n",
"\n",
"\n",
"@task\n",
"def load_data():\n",
" from sklearn.datasets import load_wine\n",
Expand Down
8 changes: 8 additions & 0 deletions rubicon_ml/workflow/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import warnings

warnings.warn(
ryanSoley marked this conversation as resolved.
Show resolved Hide resolved
"The `rubicon_ml.workflow` module is deprecated and will be removed in an upcoming release. "
"`rubicon_ml` can still be leveraged within custom tasks "
"(see https://capitalone.github.io/rubicon-ml/integrations/integration-prefect-workflows.html).",
DeprecationWarning,
)
10 changes: 10 additions & 0 deletions rubicon_ml/workflow/prefect/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import warnings


def _check_for_prefect_extras():
try:
import prefect # noqa F401
Expand All @@ -8,6 +11,13 @@ def _check_for_prefect_extras():
raise ImportError(message)


warnings.warn(
"The `rubicon_ml.workflow.prefect` module is deprecated and will be removed in an upcoming release."
shania-m marked this conversation as resolved.
Show resolved Hide resolved
"`rubicon_ml` can still be leveraged within custom tasks. "
"(see https://capitalone.github.io/rubicon-ml/integrations/integration-prefect-workflows.html).",
DeprecationWarning,
)

_check_for_prefect_extras()

from rubicon_ml.workflow.prefect.tasks import ( # noqa E402
Expand Down
9 changes: 9 additions & 0 deletions rubicon_ml/workflow/prefect/tasks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import warnings

from prefect import task

from rubicon_ml import Rubicon

warnings.warn(
"The `rubicon_ml.workflow.prefect.tasks` module is deprecated and will be removed in an upcoming release."
shania-m marked this conversation as resolved.
Show resolved Hide resolved
"`rubicon_ml` can still be leveraged within custom tasks. "
"(see https://capitalone.github.io/rubicon-ml/integrations/integration-prefect-workflows.html).",
DeprecationWarning,
)


@task
def get_or_create_project_task(
Expand Down
16 changes: 15 additions & 1 deletion tests/unit/workflow/prefect/test_prefect.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import importlib
import sys
from unittest.mock import patch

import pytest

from rubicon_ml.workflow.prefect import _check_for_prefect_extras
from rubicon_ml import workflow
from rubicon_ml.workflow import prefect
from rubicon_ml.workflow.prefect import _check_for_prefect_extras, tasks


def test_deprecations():
with pytest.deprecated_call():
importlib.reload(workflow)

with pytest.deprecated_call():
importlib.reload(prefect)

with pytest.deprecated_call():
importlib.reload(tasks)


def test_missing_prefect_extra_raises_error():
Expand Down
Loading