HierarchyService
HierarchyService(rest)
Bases: ObjectService
Service to handle Object Updates for TM1 Hierarchies
Source code in TM1py/Services/HierarchyService.py
EDGES_WORKAROUND_VERSIONS = ('11.0.002', '11.0.003', '11.1.000')
class-attribute
instance-attribute
HIERARCHY_SORT_ORDER_ARGUMENTS = CaseAndSpaceInsensitiveDict({'CompSortType': CaseAndSpaceInsensitiveSet(['ByInput', 'ByName']), 'CompSortSense': CaseAndSpaceInsensitiveSet(['Ascending', 'Descending']), 'ElSortType': CaseAndSpaceInsensitiveSet(['ByInput', 'ByName', 'ByLevel', 'ByHierarchy']), 'ElSortSense': CaseAndSpaceInsensitiveSet(['Ascending', 'Descending'])})
class-attribute
instance-attribute
elements = ElementService(rest)
instance-attribute
subsets = SubsetService(rest)
instance-attribute
add_edges(dimension_name, hierarchy_name=None, edges=None, **kwargs)
Add Edges to hierarchy. Fails if one edge already exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_name
|
str
|
|
required |
hierarchy_name
|
str
|
|
None
|
edges
|
Dict[Tuple[str, str], int]
|
|
None
|
Returns:
| Type | Description |
|---|---|
Response
|
|
Source code in TM1py/Services/HierarchyService.py
add_element_attributes(dimension_name, hierarchy_name, element_attributes, **kwargs)
Add element attributes to hierarchy. Fails if one element attribute already exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_name
|
str
|
|
required |
hierarchy_name
|
str
|
|
required |
element_attributes
|
List[ElementAttribute]
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in TM1py/Services/HierarchyService.py
add_elements(dimension_name, hierarchy_name, elements, **kwargs)
Add elements to hierarchy. Fails if one element already exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_name
|
str
|
|
required |
hierarchy_name
|
str
|
|
required |
elements
|
List[Element]
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in TM1py/Services/HierarchyService.py
create(hierarchy, **kwargs)
Create a hierarchy in an existing dimension
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hierarchy
|
Hierarchy
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in TM1py/Services/HierarchyService.py
delete(dimension_name, hierarchy_name, **kwargs)
exists(dimension_name, hierarchy_name, **kwargs)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_name
|
str
|
|
required |
hierarchy_name
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in TM1py/Services/HierarchyService.py
get(dimension_name, hierarchy_name, **kwargs)
get hierarchy
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_name
|
str
|
name of the dimension |
required |
hierarchy_name
|
str
|
name of the hierarchy |
required |
Returns:
| Type | Description |
|---|---|
Hierarchy
|
|
Source code in TM1py/Services/HierarchyService.py
get_all_names(dimension_name, **kwargs)
get all names of existing Hierarchies in a dimension
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_name
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
|
Source code in TM1py/Services/HierarchyService.py
get_cell_service()
get_default_member(dimension_name, hierarchy_name=None, **kwargs)
Get the defined default_member for a Hierarchy. Will return the element with index 1, if default member is not specified explicitly in }HierarchyProperty Cube
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_name
|
str
|
|
required |
hierarchy_name
|
str
|
|
None
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
String, name of Member |
Source code in TM1py/Services/HierarchyService.py
get_dimension_service()
get_hierarchy_summary(dimension_name, hierarchy_name, **kwargs)
Source code in TM1py/Services/HierarchyService.py
is_balanced(dimension_name, hierarchy_name, **kwargs)
Check if hierarchy is balanced
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_name
|
str
|
|
required |
hierarchy_name
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in TM1py/Services/HierarchyService.py
remove_all_edges(dimension_name, hierarchy_name=None, **kwargs)
Source code in TM1py/Services/HierarchyService.py
remove_edges_under_consolidation(dimension_name, hierarchy_name, consolidation_element, **kwargs)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_name
|
str
|
Name of the dimension |
required |
hierarchy_name
|
str
|
Name of the hierarchy |
required |
consolidation_element
|
str
|
Name of the Consolidated element |
required |
Returns:
| Type | Description |
|---|---|
List[Response]
|
response |
Source code in TM1py/Services/HierarchyService.py
update(hierarchy, keep_existing_attributes=False, **kwargs)
update a hierarchy. It's a two step process: 1. Update Hierarchy 2. Update Element-Attributes
Function caters for Bug with Edge Creation: https://www.ibm.com/developerworks/community/forums/html/topic?id=75f2b99e-6961-4c71-9364-1d5e1e083eff
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hierarchy
|
Hierarchy
|
instance of TM1py.Hierarchy |
required |
keep_existing_attributes
|
True to make sure existing attributes are not removed |
False
|
Returns:
| Type | Description |
|---|---|
List[Response]
|
list of responses |
Source code in TM1py/Services/HierarchyService.py
update_default_member(dimension_name, hierarchy_name=None, member_name='', **kwargs)
Update the default member of a hierarchy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_name
|
str
|
|
required |
hierarchy_name
|
str
|
|
None
|
member_name
|
str
|
|
''
|
Returns:
| Type | Description |
|---|---|
Response
|
|
Source code in TM1py/Services/HierarchyService.py
update_element_attributes(hierarchy, keep_existing_attributes=False, **kwargs)
Update the elementattributes of a hierarchy
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hierarchy
|
Hierarchy
|
Instance of TM1py.Hierarchy |
required |
keep_existing_attributes
|
True to make sure existing attributes are not removed |
False
|
Returns:
| Type | Description |
|---|---|
|
|
Source code in TM1py/Services/HierarchyService.py
update_or_create(hierarchy, **kwargs)
update if exists else create
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hierarchy
|
Hierarchy
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
Source code in TM1py/Services/HierarchyService.py
update_or_create_hierarchy_from_dataframe(dimension_name, hierarchy_name, df, element_column=None, verify_unique_elements=False, verify_edges=True, element_type_column='ElementType', unwind_all=False, unwind_consolidations=None, update_attribute_types=False, hierarchy_sort_order=None, delete_orphaned_consolidations=False, **kwargs)
Update or Create a hierarchy based on a dataframe, while never deleting existing elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_name
|
str
|
Name of the dimension |
required |
hierarchy_name
|
str
|
Name of the hierarchy |
required |
df
|
DataFrame
|
pd.DataFrame the data frame. Example: | | Region | ElementType | Alias:a | Currency:s | population:n | level001 | level000 | level001_weight | level000_weight | |---:|:--------|:------------|:------------|:-----------|-------------:|:---------|:---------|----------------:|----------------:| | 0 | France | Numeric | Frankreich | EUR | 60000000 | Europe | World | 1 | 1 | | 1 | Belgium | Numeric | Schweiz | CHF | 9000000 | Europe | World | 1 | 1 | | 2 | Germany | Numeric | Deutschland | EUR | 84000000 | Europe | World | 1 | 1 | Names for the parent columns (level001, level000) are not configurable and |
required |
element_type_column
|
str
|
str The column name in the df which specifies which element is which type. If None, all will be considered N level. |
'ElementType'
|
element_column
|
str
|
str The column name of the element ID. If None, assumes first column is the element ID. |
None
|
verify_unique_elements
|
bool
|
Abort early if element names are not unique |
False
|
verify_edges
|
bool
|
Abort early if edges contain a circular reference. |
True
|
unwind_all
|
bool
|
bool Unwind hierarch before creating new edges |
False
|
unwind_consolidations
|
Iterable
|
list Unwind a list of specific consolidations in the hierarchy before creating new edges, if unwind_all is true, this list is ignored |
None
|
update_attribute_types
|
bool
|
bool If True, function will delete and recreate attributes when a type change is requested. By default, function will not delete attributes. |
False
|
hierarchy_sort_order
|
Tuple[str, str, str, str]
|
Dict Pass a Tuple with 4 values for: |
None
|
delete_orphaned_consolidations
|
bool
|
bool If True, function will delete c elements that will have no children and will have no parents post update. By default, function will not delete orphaned consolidations. |
False
|
Returns:
| Type | Description |
|---|---|
|
|
Source code in TM1py/Services/HierarchyService.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 | |