Skip to content

Commit

Permalink
Update HierarchyService.py for bug #1174 and add feature #1170
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mr-SabyasachiBose authored Oct 17, 2024
1 parent a91897b commit f48c15a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions TM1py/Services/HierarchyService.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit f48c15a

Please sign in to comment.