From f48c15a9e60f1f928c4ac3d0fa400610696fa100 Mon Sep 17 00:00:00 2001 From: Sabyasachi Bose <115294043+Mr-SabyasachiBose@users.noreply.github.com> Date: Thu, 17 Oct 2024 03:14:38 +0100 Subject: [PATCH] Update HierarchyService.py for bug #1174 and add feature #1170 Bug fix for issue #1174 added to consider element names with case and space insensitive for remove_edges_under_consolidation() Feature for #1170 added to allow a list of specific consolidations to unwind --- TM1py/Services/HierarchyService.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/TM1py/Services/HierarchyService.py b/TM1py/Services/HierarchyService.py index 1fab40a9..4523bb1f 100644 --- a/TM1py/Services/HierarchyService.py +++ b/TM1py/Services/HierarchyService.py @@ -356,9 +356,10 @@ def remove_edges_under_consolidation(self, dimension_name: str, hierarchy_name: elements_under_consolidations = element_service.get_members_under_consolidation(dimension_name, hierarchy_name, consolidation_element) elements_under_consolidations.append(consolidation_element) + elements_under_consolidations = [member.lower().replace(' ','') for member in elements_under_consolidations] remove_edges = [] for (parent, component) in hierarchy.edges: - if parent in elements_under_consolidations and component in elements_under_consolidations: + if parent.lower().replace(' ','') in elements_under_consolidations and component.lower().replace(' ','') in elements_under_consolidations: remove_edges.append((parent, component)) hierarchy.remove_edges(remove_edges) return self.update(hierarchy, **kwargs) @@ -428,7 +429,7 @@ def update_or_create_hierarchy_from_dataframe( verify_edges: bool = True, element_type_column: str = 'ElementType', unwind: bool = False, - unwind_consol: str = '', + unwind_consol: list = [], update_attribute_types: bool = False): """ Update or Create a hierarchy based on a dataframe, while never deleting existing elements. @@ -460,6 +461,8 @@ def update_or_create_hierarchy_from_dataframe( Unwind hierarch before creating new edges :param unwind_consol: str Unwind specific consolidation in hierarch before creating new edges, if unwind == True then this override is ignored and entire hierarch is unwinded + :param unwind_consol: list + Unwind specific consolidations in hierarch before creating new edges, if this argument is blank, and unwind is true, Unwind entire hiera :param update_attribute_types: bool If True, function will delete and recreate attributes when a type change is requested. By default, function will not delete attributes. @@ -638,10 +641,12 @@ def update_or_create_hierarchy_from_dataframe( use_blob=True) if unwind: - self.remove_all_edges(dimension_name, hierarchy_name) - - if unwind_consol.strip() != '' and unwind == False: - self.remove_edges_under_consolidation(dimension_name, hierarchy_name, unwind_consol) + if len(unwind_consol) == 0: + self.remove_all_edges(dimension_name, hierarchy_name) + else: + for elem in unwind_consol: + if self.elements.exists(dimension_name, hierarchy_name, elem): + self.remove_edges_under_consolidation(dimension_name, hierarchy_name, elem) edges = CaseAndSpaceInsensitiveTuplesDict() for element_name, *record in df[[element_column, *level_columns, *level_weight_columns]].itertuples(