From 4d5457436402931df502da701a27692c9b4dedfc Mon Sep 17 00:00:00 2001 From: Ryan Soley Date: Wed, 4 Sep 2024 10:14:28 -0400 Subject: [PATCH 1/4] deprecate module --- rubicon_ml/workflow/__init__.py | 7 +++++++ rubicon_ml/workflow/prefect/__init__.py | 9 +++++++++ rubicon_ml/workflow/prefect/tasks.py | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/rubicon_ml/workflow/__init__.py b/rubicon_ml/workflow/__init__.py index e69de29b..5f0c79c3 100644 --- a/rubicon_ml/workflow/__init__.py +++ b/rubicon_ml/workflow/__init__.py @@ -0,0 +1,7 @@ +import warnings + +warnings.warn( + "The `rubicon_ml.workflow` module is deprecated and will be removed in an upcoming release. " + "`rubicon_ml` can still be leveraged within custom tasks.", + DeprecationWarning, +) diff --git a/rubicon_ml/workflow/prefect/__init__.py b/rubicon_ml/workflow/prefect/__init__.py index 9e131fcb..c4fe7d29 100644 --- a/rubicon_ml/workflow/prefect/__init__.py +++ b/rubicon_ml/workflow/prefect/__init__.py @@ -1,3 +1,6 @@ +import warnings + + def _check_for_prefect_extras(): try: import prefect # noqa F401 @@ -8,6 +11,12 @@ 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." + "`rubicon_ml` can still be leveraged within custom tasks.", + DeprecationWarning, +) + _check_for_prefect_extras() from rubicon_ml.workflow.prefect.tasks import ( # noqa E402 diff --git a/rubicon_ml/workflow/prefect/tasks.py b/rubicon_ml/workflow/prefect/tasks.py index d7bb6b99..a05649e1 100644 --- a/rubicon_ml/workflow/prefect/tasks.py +++ b/rubicon_ml/workflow/prefect/tasks.py @@ -1,7 +1,15 @@ +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." + "`rubicon_ml` can still be leveraged within custom tasks.", + DeprecationWarning, +) + @task def get_or_create_project_task( From 62dbc2f211a02216764a9c403c1c4cdb73011dea Mon Sep 17 00:00:00 2001 From: Ryan Soley Date: Wed, 4 Sep 2024 10:15:09 -0400 Subject: [PATCH 2/4] move full tasks into notebook example --- .../integration-prefect-workflows.ipynb | 65 +++++++++++++++---- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/notebooks/integrations/integration-prefect-workflows.ipynb b/notebooks/integrations/integration-prefect-workflows.ipynb index 4c7d029a..92ef2159 100644 --- a/notebooks/integrations/integration-prefect-workflows.ipynb +++ b/notebooks/integrations/integration-prefect-workflows.ipynb @@ -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." ] }, { @@ -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)" ] }, { @@ -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", From a5ede1e228407d799abbade87a514d165d185c7f Mon Sep 17 00:00:00 2001 From: Ryan Soley Date: Wed, 4 Sep 2024 10:17:08 -0400 Subject: [PATCH 3/4] mention example in deprecation message --- rubicon_ml/workflow/__init__.py | 3 ++- rubicon_ml/workflow/prefect/__init__.py | 3 ++- rubicon_ml/workflow/prefect/tasks.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/rubicon_ml/workflow/__init__.py b/rubicon_ml/workflow/__init__.py index 5f0c79c3..24588bfb 100644 --- a/rubicon_ml/workflow/__init__.py +++ b/rubicon_ml/workflow/__init__.py @@ -2,6 +2,7 @@ warnings.warn( "The `rubicon_ml.workflow` module is deprecated and will be removed in an upcoming release. " - "`rubicon_ml` can still be leveraged within custom tasks.", + "`rubicon_ml` can still be leveraged within custom tasks " + "(see https://capitalone.github.io/rubicon-ml/integrations/integration-prefect-workflows.html).", DeprecationWarning, ) diff --git a/rubicon_ml/workflow/prefect/__init__.py b/rubicon_ml/workflow/prefect/__init__.py index c4fe7d29..7dc8d919 100644 --- a/rubicon_ml/workflow/prefect/__init__.py +++ b/rubicon_ml/workflow/prefect/__init__.py @@ -13,7 +13,8 @@ def _check_for_prefect_extras(): warnings.warn( "The `rubicon_ml.workflow.prefect` module is deprecated and will be removed in an upcoming release." - "`rubicon_ml` can still be leveraged within custom tasks.", + "`rubicon_ml` can still be leveraged within custom tasks. " + "(see https://capitalone.github.io/rubicon-ml/integrations/integration-prefect-workflows.html).", DeprecationWarning, ) diff --git a/rubicon_ml/workflow/prefect/tasks.py b/rubicon_ml/workflow/prefect/tasks.py index a05649e1..14f5805f 100644 --- a/rubicon_ml/workflow/prefect/tasks.py +++ b/rubicon_ml/workflow/prefect/tasks.py @@ -6,7 +6,8 @@ warnings.warn( "The `rubicon_ml.workflow.prefect.tasks` module is deprecated and will be removed in an upcoming release." - "`rubicon_ml` can still be leveraged within custom tasks.", + "`rubicon_ml` can still be leveraged within custom tasks. " + "(see https://capitalone.github.io/rubicon-ml/integrations/integration-prefect-workflows.html).", DeprecationWarning, ) From 4d4a9bd053caac3dfb445abffeeb10c970d3bcd6 Mon Sep 17 00:00:00 2001 From: Ryan Soley Date: Thu, 5 Sep 2024 12:17:38 -0400 Subject: [PATCH 4/4] add test --- tests/unit/workflow/prefect/test_prefect.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/unit/workflow/prefect/test_prefect.py b/tests/unit/workflow/prefect/test_prefect.py index e64e9fc5..d624f33c 100644 --- a/tests/unit/workflow/prefect/test_prefect.py +++ b/tests/unit/workflow/prefect/test_prefect.py @@ -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():