From b5045afa52c13fde179d30b9873c40335fca7d78 Mon Sep 17 00:00:00 2001 From: "Eric T. Johnson" Date: Fri, 7 Apr 2023 14:37:31 -0400 Subject: [PATCH] FIX: make sure find_lowest_subclasses doesn't add extra classes If a child class and its grandparent are both in candidates, the previous implementation would return both the child class and the parent class. --- yt/utilities/hierarchy_inspection.py | 2 +- yt/utilities/tests/test_hierarchy_inspection.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/yt/utilities/hierarchy_inspection.py b/yt/utilities/hierarchy_inspection.py index 7e62ed1684f..8a2e0aae92f 100644 --- a/yt/utilities/hierarchy_inspection.py +++ b/yt/utilities/hierarchy_inspection.py @@ -39,4 +39,4 @@ def find_lowest_subclasses(candidates: List[Type]) -> List[Type]: count = reduce(lambda x, y: x + y, counters) - return [x for x in count.keys() if count[x] == 1] + return [x for x in candidates if count[x] == 1] diff --git a/yt/utilities/tests/test_hierarchy_inspection.py b/yt/utilities/tests/test_hierarchy_inspection.py index 8f7d7510e61..c5d36f90952 100644 --- a/yt/utilities/tests/test_hierarchy_inspection.py +++ b/yt/utilities/tests/test_hierarchy_inspection.py @@ -55,3 +55,9 @@ def test_diverging_tree(): result = find_lowest_subclasses([level1, level2, level3, level1a]) assert len(result) == 2 assert level1a in result and level3 in result + + +def test_without_parents(): + result = find_lowest_subclasses([level1, level3]) + assert len(result) == 1 + assert level3 in result