-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add ability to blacklist params. also sanitise keys #595
Merged
Galileo-Galilei
merged 14 commits into
Galileo-Galilei:master
from
pascalwhoop:feat/blacklistable-params
Oct 23, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ec4be9d
add ability to blacklist params. also sanitise keys
pascalwhoop 4f63778
Merge remote-tracking branch 'origin/master' into feat/blacklistable-…
pascalwhoop b7c1a96
rm dropping secret params
pascalwhoop f3ce52f
rm lint
pascalwhoop 180de67
rm empty l
pascalwhoop 68e09e8
rm docs
pascalwhoop fa804eb
add regex
pascalwhoop 936155e
add testsd
pascalwhoop cade901
resolve nitpicks
Galileo-Galilei 034bd0c
fix typo
Galileo-Galilei e9b93fc
fix test on windows
Galileo-Galilei 50c7eb0
Merge branch 'master' into feat/blacklistable-params
Galileo-Galilei fbb882c
remove platform specific tests for sanitization
Galileo-Galilei 16fb132
add changelog entries
Galileo-Galilei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import os | ||
from pathlib import Path | ||
from typing import Dict | ||
|
||
|
@@ -74,6 +75,136 @@ def dummy_catalog(): | |
return catalog | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"param_name,expected_name", | ||
[ | ||
("valid_param", "valid_param"), | ||
("valid-param", "valid-param"), | ||
("invalid/param", "invalid/param"), | ||
("invalid.param", "invalid.param"), | ||
("[invalid]$param", "_invalid__param"), | ||
], | ||
) | ||
def test_parameter_name_sanitization( | ||
kedro_project, dummy_run_params, param_name, expected_name | ||
): | ||
mlflow_tracking_uri = (kedro_project / "mlruns").as_uri() | ||
mlflow.set_tracking_uri(mlflow_tracking_uri) | ||
|
||
node_inputs = {f"params:{param_name}": "test_value"} | ||
|
||
bootstrap_project(kedro_project) | ||
with KedroSession.create( | ||
project_path=kedro_project, | ||
) as session: | ||
context = session.load_context() | ||
mlflow_node_hook = MlflowHook() | ||
mlflow_node_hook.after_context_created(context) | ||
|
||
with mlflow.start_run(): | ||
mlflow_node_hook.before_pipeline_run( | ||
run_params=dummy_run_params, | ||
pipeline=Pipeline([]), | ||
catalog=DataCatalog(), | ||
) | ||
mlflow_node_hook.before_node_run( | ||
node=node(func=lambda x: x, inputs=dict(x="a"), outputs=None), | ||
catalog=DataCatalog(), | ||
inputs=node_inputs, | ||
is_async=False, | ||
) | ||
run_id = mlflow.active_run().info.run_id | ||
|
||
mlflow_client = MlflowClient(mlflow_tracking_uri) | ||
current_run = mlflow_client.get_run(run_id) | ||
assert expected_name in current_run.data.params | ||
assert current_run.data.params[expected_name] == "test_value" | ||
|
||
|
||
@pytest.mark.skipif( | ||
os.name != "nt", reason="Windows does not log params with colon symbol" | ||
) | ||
def test_parameter_name_with_colon_sanitization_on_windows( | ||
kedro_project, dummy_run_params | ||
): | ||
param_name = "valid:param" | ||
expected_name = "valid_param" | ||
|
||
mlflow_tracking_uri = (kedro_project / "mlruns").as_uri() | ||
mlflow.set_tracking_uri(mlflow_tracking_uri) | ||
|
||
node_inputs = {f"params:{param_name}": "test_value"} | ||
|
||
bootstrap_project(kedro_project) | ||
with KedroSession.create( | ||
project_path=kedro_project, | ||
) as session: | ||
context = session.load_context() | ||
mlflow_node_hook = MlflowHook() | ||
mlflow_node_hook.after_context_created(context) | ||
|
||
with mlflow.start_run(): | ||
mlflow_node_hook.before_pipeline_run( | ||
run_params=dummy_run_params, | ||
pipeline=Pipeline([]), | ||
catalog=DataCatalog(), | ||
) | ||
mlflow_node_hook.before_node_run( | ||
node=node(func=lambda x: x, inputs=dict(x="a"), outputs=None), | ||
catalog=DataCatalog(), | ||
inputs=node_inputs, | ||
is_async=False, | ||
) | ||
run_id = mlflow.active_run().info.run_id | ||
|
||
mlflow_client = MlflowClient(mlflow_tracking_uri) | ||
current_run = mlflow_client.get_run(run_id) | ||
assert expected_name in current_run.data.params | ||
assert current_run.data.params[expected_name] == "test_value" | ||
|
||
|
||
@pytest.mark.skipif( | ||
os.name == "nt", reason="Linux and Mac do log params with colon symbol" | ||
) | ||
def test_parameter_name_with_colon_sanitization_on_mac_linux( | ||
kedro_project, dummy_run_params | ||
): | ||
param_name = "valid:param" | ||
expected_name = "valid:param" | ||
|
||
mlflow_tracking_uri = (kedro_project / "mlruns").as_uri() | ||
mlflow.set_tracking_uri(mlflow_tracking_uri) | ||
|
||
node_inputs = {f"params:{param_name}": "test_value"} | ||
|
||
bootstrap_project(kedro_project) | ||
with KedroSession.create( | ||
project_path=kedro_project, | ||
) as session: | ||
context = session.load_context() | ||
mlflow_node_hook = MlflowHook() | ||
mlflow_node_hook.after_context_created(context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure you need after_context_created since you already set Overall really like the test👍 |
||
|
||
with mlflow.start_run(): | ||
mlflow_node_hook.before_pipeline_run( | ||
run_params=dummy_run_params, | ||
pipeline=Pipeline([]), | ||
catalog=DataCatalog(), | ||
) | ||
mlflow_node_hook.before_node_run( | ||
node=node(func=lambda x: x, inputs=dict(x="a"), outputs=None), | ||
catalog=DataCatalog(), | ||
inputs=node_inputs, | ||
is_async=False, | ||
) | ||
run_id = mlflow.active_run().info.run_id | ||
|
||
mlflow_client = MlflowClient(mlflow_tracking_uri) | ||
current_run = mlflow_client.get_run(run_id) | ||
assert expected_name in current_run.data.params | ||
assert current_run.data.params[expected_name] == "test_value" | ||
|
||
|
||
def test_pipeline_run_hook_getting_configs( | ||
kedro_project, | ||
dummy_run_params, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nitpick, but can we just ignore all this? Since you invoke the hook manually, I don't think it's necessary creating a whole session and contexte, unless I miss something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, this is needed to call the after_context_created hook, which format and stores the entire configuration.