From 642984d700d974111db4840f778a2aba0564b535 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Mon, 24 Jun 2024 13:07:37 +0200 Subject: [PATCH] DOC: utils.hash() is not influenced by names (#443) * DOC: utils.hash() is not influenced by names * Improve wording --- audformat/core/utils.py | 3 ++- tests/test_utils.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/audformat/core/utils.py b/audformat/core/utils.py index fdb0b411..b201808a 100644 --- a/audformat/core/utils.py +++ b/audformat/core/utils.py @@ -669,7 +669,8 @@ def hash( Objects with the same elements produce the same hash string - independent of the ordering of the elements. + independent of the ordering of the elements, + and level or column names. Args: obj: object diff --git a/tests/test_utils.py b/tests/test_utils.py index d56c69c8..d124e057 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -477,6 +477,38 @@ def test_expand_file_path(tmpdir, index, root, expected): ), "-103439349488189352", ), + (pd.Index([0, 1], name="idx"), "6238072747940578789"), + (pd.Index([0, 1], name="name"), "6238072747940578789"), + ( + pd.MultiIndex.from_arrays( + [[0, 1], ["a", "b"]], + names=["idx1", "idx2"], + ), + "8378370490910668918", + ), + ( + pd.MultiIndex.from_arrays( + [[0, 1], ["a", "b"]], + names=["name1", "name2"], + ), + "8378370490910668918", + ), + ( + pd.Series([0, 1], name="series"), + "-7179254265801896228", + ), + ( + pd.Series([0, 1], name="name"), + "-7179254265801896228", + ), + ( + pd.DataFrame([0, 1], columns=["frame"]), + "-7179254265801896228", + ), + ( + pd.DataFrame([0, 1], columns=["name"]), + "-7179254265801896228", + ), ], ) def test_hash(obj, expected):