-
Notifications
You must be signed in to change notification settings - Fork 118
Update SubsetService.py #1270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update SubsetService.py #1270
Conversation
Add parameter to get elements dynamically from subset object
|
What do you think about merging the def get_element_names(
self,
dimension_name: str,
hierarchy_name: str,
subset: Union[str, "Subset"],
private: bool = False,
**kwargs
) -> List[str]:
"""
Retrieve element names from a static or dynamic subset.
:param dimension_name: Name of the dimension.
:param hierarchy_name: Name of the hierarchy.
:param subset: Subset name (str) or Subset object.
:param private: Whether the subset is private.
:param kwargs: Additional arguments.
:return: List of element names.
"""
if isinstance(subset, str):
subset = self.get(subset, dimension_name, hierarchy_name, private=private, **kwargs)
elif not isinstance(subset, Subet):
raise ValueError(...)
if subset.is_static:
return list(subset_obj.elements)
element_service = ElementService(self._rest)
tuples = element_service.execute_set_mdx(
mdx=subset_obj.expression,
member_properties=["Name"],
element_properties=None,
parent_properties=None,
**kwargs
)
return [entry[0].get("Name", "") for entry in tuples if entry and "Name" in entry[0]] |
|
I think that's a great idea! |
Modified argument options for get_element_names Added `update_static_elements()` Modified `update()` to use `update_static_elements()` to reduce number of requests from 2 to 1 for static subset updates
|
Modified argument options for get_element_names |
MariusWirtz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider my feedback and make sure the tests in SubsetService_test.py execute successfully.
TM1py/Services/SubsetService.py
Outdated
| @@ -1,5 +1,5 @@ | |||
| # -*- coding: utf-8 -*- | |||
| from typing import List | |||
| from typing import List, Optional, Union, Iterable | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're missing 2 imports
import json
from TM1py.Objects import Element
TM1py/Services/SubsetService.py
Outdated
| subset = self.get(subset_name, dimension_name, hierarchy_name, private=private, **kwargs) | ||
| if isinstance(subset, str): | ||
| subset = self.get(subset, dimension_name, hierarchy_name, private=private, **kwargs) | ||
| elif not isinstance(subset, Subet): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: this should be Subset
| subset_name = subset | ||
| else: | ||
| raise ValueError(f"subset argument must be of type 'str' or 'Subset', not '{type(subset)}'") | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If dimension_name and hierarchy_name is not provided as arguments to the function, I think you should try to derive it from the subset object.
if subset is provided as string but dimension_name and hierarchy_name are missing it should raise a ValueError
makes sense Copi Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Add parameter to get elements dynamically from subset object