Skip to content

Conversation

@Mr-SabyasachiBose
Copy link
Contributor

remove_edges_under_consolidation() is not case and space insensitive at the moment, this fix would allow the function to be case and space insensitive.

e.g. Element name "Parent1", "parent 1", "Parent 1", "PARENT1" would be treated in the same way.

Added/modified coding in HierarchyService.py to allow the function to work in case and space insensitive nature.

from TM1py.Utils.Utils import case_and_space_insensitive_equals, format_url, CaseAndSpaceInsensitiveDict, \
    CaseAndSpaceInsensitiveSet, CaseAndSpaceInsensitiveTuplesDict, require_pandas, require_data_admin, \
    lower_and_drop_spaces, require_ops_admin, verify_version

...


    def remove_edges_under_consolidation(self, dimension_name: str, hierarchy_name: str,
                                         consolidation_element: str, **kwargs) -> List[Response]:
        """
        :param dimension_name: Name of the dimension
        :param hierarchy_name: Name of the hierarchy
        :param consolidation_element: Name of the Consolidated element
        :return: response
        """
        hierarchy = self.get(dimension_name, hierarchy_name)
        from TM1py.Services import ElementService
        element_service = ElementService(self._rest)
        elements_under_consolidations = element_service.get_members_under_consolidation(dimension_name, hierarchy_name,
                                                                                        consolidation_element)                                                            
        elements_under_consolidations.append(consolidation_element)
        elements_under_consolidations = [lower_and_drop_spaces(member) for member in elements_under_consolidations]
        remove_edges = []
        for (parent, component) in hierarchy.edges:
            if lower_and_drop_spaces(parent) in elements_under_consolidations and lower_and_drop_spaces(component) in elements_under_consolidations:
                remove_edges.append((parent, component))
        hierarchy.remove_edges(remove_edges)
        return self.update(hierarchy, **kwargs)

…or element in remove_edges_under_consolidation()

remove_edges_under_consolidation() is not case and space insensitive at the moment, this fix would allow the function to be case and space insensitive. 

e.g. Element name "Parent1", "parent 1", "Parent   1", "PARENT1" would be treated in the same way.
@Mr-SabyasachiBose Mr-SabyasachiBose changed the title Fix 1174: Bug fix to compare and allow case and space insensitively for remove_edges_under_consolidation() Fix 1174: Bug fix to compare and allow case and space insensitivity for remove_edges_under_consolidation() Oct 17, 2024
@MariusWirtz
Copy link
Collaborator

It would be more efficient to store the elements_under_consolidations as a CaseAndSpaceInsensitiveSet.

The is in operation is faster on a set than on a list, and it implicitly handles TM1's case and space insensitivity.

…itiveSet

Updated elements_under_consolidations as a CaseAndSpaceInsensitiveSet as Marius suggested
@Mr-SabyasachiBose
Copy link
Contributor Author

It would be more efficient to store the elements_under_consolidations as a CaseAndSpaceInsensitiveSet.

The is in operation is faster on a set than on a list, and it implicitly handles TM1's case and space insensitivity.

@MariusWirtz I have updated this as per suggestion, could you please review?

@MariusWirtz MariusWirtz merged commit db745b2 into cubewise-code:master Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants