Skip to content

Commit 32d1a83

Browse files
authored
deprecate prefect tasks (#483)
* deprecate module * move full tasks into notebook example * mention example in deprecation message * add test
1 parent 7394403 commit 32d1a83

File tree

5 files changed

+93
-15
lines changed

5 files changed

+93
-15
lines changed

notebooks/integrations/integration-prefect-workflows.ipynb

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"\n",
3030
"### Setting up a simple flow\n",
3131
"\n",
32-
"Now we can get started! Creating Prefect **tasks** is easy enough on its own, but we've added\n",
33-
"some simple ones to the ``rubicon_ml`` library."
32+
"Now we can get started! Let's create some simple Prefect **tasks** for the core ``rubcion_ml`` loggers."
3433
]
3534
},
3635
{
@@ -39,15 +38,56 @@
3938
"metadata": {},
4039
"outputs": [],
4140
"source": [
42-
"from rubicon_ml.workflow.prefect import (\n",
43-
" get_or_create_project_task,\n",
44-
" create_experiment_task,\n",
45-
" log_artifact_task,\n",
46-
" log_dataframe_task,\n",
47-
" log_feature_task,\n",
48-
" log_metric_task,\n",
49-
" log_parameter_task,\n",
50-
")"
41+
"\n",
42+
"from prefect import task\n",
43+
"\n",
44+
"\n",
45+
"@task\n",
46+
"def get_or_create_project_task(\n",
47+
" persistence, root_dir, project_name, auto_git_enabled=False, storage_options={}, **kwargs\n",
48+
"):\n",
49+
" from rubicon_ml import Rubicon\n",
50+
"\n",
51+
"\n",
52+
" rubicon = Rubicon(\n",
53+
" persistence=persistence,\n",
54+
" root_dir=root_dir,\n",
55+
" auto_git_enabled=auto_git_enabled,\n",
56+
" **storage_options,\n",
57+
" )\n",
58+
" project = rubicon.get_or_create_project(project_name, **kwargs)\n",
59+
"\n",
60+
" return project\n",
61+
"\n",
62+
"\n",
63+
"@task\n",
64+
"def create_experiment_task(project, **kwargs):\n",
65+
" return project.log_experiment(**kwargs)\n",
66+
"\n",
67+
"\n",
68+
"@task\n",
69+
"def log_artifact_task(parent, **kwargs):\n",
70+
" return parent.log_artifact(**kwargs)\n",
71+
"\n",
72+
"\n",
73+
"@task\n",
74+
"def log_dataframe_task(parent, df, **kwargs):\n",
75+
" return parent.log_dataframe(df, **kwargs)\n",
76+
"\n",
77+
"\n",
78+
"@task\n",
79+
"def log_feature_task(experiment, feature_name, **kwargs):\n",
80+
" return experiment.log_feature(feature_name, **kwargs)\n",
81+
"\n",
82+
"\n",
83+
"@task\n",
84+
"def log_metric_task(experiment, metric_name, metric_value, **kwargs):\n",
85+
" return experiment.log_metric(metric_name, metric_value, **kwargs)\n",
86+
"\n",
87+
"\n",
88+
"@task\n",
89+
"def log_parameter_task(experiment, parameter_name, parameter_value, **kwargs):\n",
90+
" return experiment.log_parameter(parameter_name, parameter_value, **kwargs)"
5191
]
5292
},
5393
{
@@ -65,9 +105,6 @@
65105
"metadata": {},
66106
"outputs": [],
67107
"source": [
68-
"from prefect import task\n",
69-
"\n",
70-
"\n",
71108
"@task\n",
72109
"def load_data():\n",
73110
" from sklearn.datasets import load_wine\n",

rubicon_ml/workflow/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import warnings
2+
3+
warnings.warn(
4+
"The `rubicon_ml.workflow` module is deprecated and will be removed in an upcoming release. "
5+
"`rubicon_ml` can still be leveraged within custom tasks "
6+
"(see https://capitalone.github.io/rubicon-ml/integrations/integration-prefect-workflows.html).",
7+
DeprecationWarning,
8+
)

rubicon_ml/workflow/prefect/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import warnings
2+
3+
14
def _check_for_prefect_extras():
25
try:
36
import prefect # noqa F401
@@ -8,6 +11,13 @@ def _check_for_prefect_extras():
811
raise ImportError(message)
912

1013

14+
warnings.warn(
15+
"The `rubicon_ml.workflow.prefect` module is deprecated and will be removed in an upcoming release."
16+
"`rubicon_ml` can still be leveraged within custom tasks. "
17+
"(see https://capitalone.github.io/rubicon-ml/integrations/integration-prefect-workflows.html).",
18+
DeprecationWarning,
19+
)
20+
1121
_check_for_prefect_extras()
1222

1323
from rubicon_ml.workflow.prefect.tasks import ( # noqa E402

rubicon_ml/workflow/prefect/tasks.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
import warnings
2+
13
from prefect import task
24

35
from rubicon_ml import Rubicon
46

7+
warnings.warn(
8+
"The `rubicon_ml.workflow.prefect.tasks` module is deprecated and will be removed in an upcoming release."
9+
"`rubicon_ml` can still be leveraged within custom tasks. "
10+
"(see https://capitalone.github.io/rubicon-ml/integrations/integration-prefect-workflows.html).",
11+
DeprecationWarning,
12+
)
13+
514

615
@task
716
def get_or_create_project_task(

tests/unit/workflow/prefect/test_prefect.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
import importlib
12
import sys
23
from unittest.mock import patch
34

45
import pytest
56

6-
from rubicon_ml.workflow.prefect import _check_for_prefect_extras
7+
from rubicon_ml import workflow
8+
from rubicon_ml.workflow import prefect
9+
from rubicon_ml.workflow.prefect import _check_for_prefect_extras, tasks
10+
11+
12+
def test_deprecations():
13+
with pytest.deprecated_call():
14+
importlib.reload(workflow)
15+
16+
with pytest.deprecated_call():
17+
importlib.reload(prefect)
18+
19+
with pytest.deprecated_call():
20+
importlib.reload(tasks)
721

822

923
def test_missing_prefect_extra_raises_error():

0 commit comments

Comments
 (0)