From dd2d2dce198b9ee48ad27059932c4cb630f3bd0c Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Wed, 18 Jan 2023 17:50:37 +0100 Subject: [PATCH] param: Fix status check for Tuples. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #8803 Update dvc/dependency/param.py Co-authored-by: Peter Rowlands (변기호) --- dvc/dependency/param.py | 9 +++++++-- tests/unit/dependency/test_params.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/dvc/dependency/param.py b/dvc/dependency/param.py index 0247f18f7..d38a0af32 100644 --- a/dvc/dependency/param.py +++ b/dvc/dependency/param.py @@ -125,9 +125,14 @@ class ParamsDependency(Dependency): elif param not in info: st = "new" elif actual[param] != info[param]: - st = "modified" + if ( + isinstance(actual[param], tuple) + and list(actual[param]) == info[param] + ): + continue + else: + st = "modified" else: - assert actual[param] == info[param] continue status[str(self)][param] = st diff --git a/tests/unit/dependency/test_params.py b/tests/unit/dependency/test_params.py index d2a9b0a9f..de95d46b9 100644 --- a/tests/unit/dependency/test_params.py +++ b/tests/unit/dependency/test_params.py @@ -207,6 +207,22 @@ def test_read_params_py(tmp_dir, dvc): assert dep.read_params() == {"x": 4, "Klass.a": "val1"} +def test_params_py_tuple_status(tmp_dir, dvc): + """https://github.com/iterative/dvc/issues/8803""" + parameters_file = "parameters.py" + tmp_dir.gen(parameters_file, "TUPLE = (10, 100)\n") + dep = ParamsDependency(Stage(dvc), parameters_file, ["TUPLE"]) + # lock file uses YAML so the tuple will be loaded as a list + dep.fill_values({"TUPLE": [10, 100]}) + assert dep.status() == {} + dep.fill_values({"TUPLE": [11, 100]}) + assert dep.status() == {"parameters.py": {"TUPLE": "modified"}} + dep.fill_values({"TUPLE": [10]}) + assert dep.status() == {"parameters.py": {"TUPLE": "modified"}} + dep.fill_values({"TUPLE": {10: "foo", 100: "bar"}}) + assert dep.status() == {"parameters.py": {"TUPLE": "modified"}} + + def test_get_hash_missing_config(dvc): dep = ParamsDependency(Stage(dvc), None, ["foo"]) with pytest.raises(MissingParamsError):