cubewise-code / tm1py

TM1py is a Python package that wraps the TM1 REST API in a simple to use library.
http://tm1py.readthedocs.io/en/latest/
MIT License
190 stars 110 forks source link

`get_elements_dataframe` on v12 fails with `use_blob=True` #1199

Open MariusWirtz opened 2 days ago

MariusWirtz commented 2 days ago

The below script works on v11 but fails on v12.

The MDX View used as the source view for the unbound TI produces a different data source in v12 compared to v11.

This needs to be raised with IBM or adjusted for in TM1py.

with TM1Service(**v12_params) as tm1:
    print(tm1.server.get_product_version())

    df = tm1.elements.get_elements_dataframe(
        dimension_name="Boardgame",
        hierarchy_name="Boardgame",
        skip_consolidations=True,
        skip_parents=False,
        skip_weights=False,
        use_blob=True
    )

    print(df.to_markdown())
WITH 
MEMBER [}ElementAttributes_Boardgame].[L000] 
AS [Boardgame].[Boardgame].CurrentMember.Parent.PROPERTIES('NAME')

MEMBER [}ElementAttributes_Boardgame].[level000_Weight]
AS IIF(
[Boardgame].[Boardgame].CurrentMember.Properties('MEMBER_WEIGHT') = '',
0,
[Boardgame].[Boardgame].CurrentMember.Properties('MEMBER_WEIGHT'))

SELECT
{ { Tm1FilterByLevel({ [Boardgame].[Boardgame].Members }, 0) } } ON ROWS,
{ {Tm1SubsetAll([}ElementAttributes_Boardgame])} + {[}ElementAttributes_Boardgame].[level000_Weight],[}ElementAttributes_Boardgame].[L000]} } ON COLUMNS
FROM [}ElementAttributes_Boardgame]  
rclapp commented 2 days ago

What is the difference in shape?

MariusWirtz commented 2 days ago

use_blob=True

with TM1Service(**v12_params) as tm1:
    print(tm1.server.get_product_version())

    df = tm1.elements.get_elements_dataframe(
        dimension_name="Boardgame",
        hierarchy_name="Boardgame",
        skip_consolidations=True,
        skip_parents=False,
        skip_weights=False,
        use_blob=True
    )

    print(df.to_markdown())
Boardgame Type ProductCode Age Players level000_Weight level000
0 Monopoly Numeric P0001 7+ >4 0 0
1 Scrabble Numeric 1 All Boardgames P0002 0 0
2 Connect4 Numeric 10+ >4 1 0 0
3 Battleship Numeric All Boardgames P0003 2+ 0 0
4 Trivial Pursuit Numeric 2 1 All Boardgames 0 0
5 Othello Numeric P0004 5+ 2 0 0
6 Risk Numeric 1 All Boardgames P0005 0 0
7 Catan Numeric 16+ >4 1 0 0
8 Cluedo Numeric All Boardgames P0006 7+ 0 0
9 Ludo Numeric 2 1 All Boardgames 0 0
10 Other Numeric P0007 16+ >4 0 0

The intermediary blob file looks like this. It seems the calculated members aren't calculated correctly when the MDX is a TI datasource.

"Boardgame"~"}ElementAttributes_Boardgame"~"Value"
"Monopoly"~"ProductCode"~"P0001"
"Monopoly"~"Age"~"7+"
"Monopoly"~"Players"~">4"
"Monopoly"~"level000_Weight"~"0"
"Monopoly"~"L000"~"0"
"Scrabble"~"ProductCode"~"1"
"Scrabble"~"Age"~"All Boardgames"
"Scrabble"~"Players"~"P0002"
"Scrabble"~"level000_Weight"~"0"
"Scrabble"~"L000"~"0"
"Connect4"~"ProductCode"~"10+"
"Connect4"~"Age"~">4"
"Connect4"~"Players"~"1"
"Connect4"~"level000_Weight"~"0"
"Connect4"~"L000"~"0"
"Battleship"~"ProductCode"~"All Boardgames"
"Battleship"~"Age"~"P0003"
"Battleship"~"Players"~"2+"
"Battleship"~"level000_Weight"~"0"
"Battleship"~"L000"~"0"
"Trivial Pursuit"~"ProductCode"~"2"
"Trivial Pursuit"~"Age"~"1"
"Trivial Pursuit"~"Players"~"All Boardgames"
"Trivial Pursuit"~"level000_Weight"~"0"
"Trivial Pursuit"~"L000"~"0"
"Othello"~"ProductCode"~"P0004"
"Othello"~"Age"~"5+"
"Othello"~"Players"~"2"
"Othello"~"level000_Weight"~"0"
"Othello"~"L000"~"0"
"Risk"~"ProductCode"~"1"
"Risk"~"Age"~"All Boardgames"
"Risk"~"Players"~"P0005"
"Risk"~"level000_Weight"~"0"
"Risk"~"L000"~"0"
"Catan"~"ProductCode"~"16+"
"Catan"~"Age"~">4"
"Catan"~"Players"~"1"
"Catan"~"level000_Weight"~"0"
"Catan"~"L000"~"0"
"Cluedo"~"ProductCode"~"All Boardgames"
"Cluedo"~"Age"~"P0006"
"Cluedo"~"Players"~"7+"
"Cluedo"~"level000_Weight"~"0"
"Cluedo"~"L000"~"0"
"Ludo"~"ProductCode"~"2"
"Ludo"~"Age"~"1"
"Ludo"~"Players"~"All Boardgames"
"Ludo"~"level000_Weight"~"0"
"Ludo"~"L000"~"0"
"Other"~"ProductCode"~"P0007"
"Other"~"Age"~"16+"
"Other"~"Players"~">4"
"Other"~"level000_Weight"~"0"
"Other"~"L000"~"0"

use_blob=False

with TM1Service(**v12_params) as tm1:
    print(tm1.server.get_product_version())

    df = tm1.elements.get_elements_dataframe(
        dimension_name="Boardgame",
        hierarchy_name="Boardgame",
        skip_consolidations=True,
        skip_parents=False,
        skip_weights=False,
        use_blob=False
    )

    print(df.to_markdown())
Boardgame Type ProductCode Age Players level000_Weight level000
0 Monopoly Numeric P0001 7+ >4 1 All Boardgames
1 Scrabble Numeric P0002 10+ >4 1 All Boardgames
2 Connect4 Numeric P0003 2+ 2 1 All Boardgames
3 Battleship Numeric P0004 5+ 2 1 All Boardgames
4 Trivial Pursuit Numeric P0005 16+ >4 1 All Boardgames
5 Othello Numeric P0006 7+ 2 1 All Boardgames
6 Risk Numeric P0007 16+ >4 1 All Boardgames
7 Catan Numeric P0008 10+ >4 1 All Boardgames
8 Cluedo Numeric P0009 7+ >4 1 All Boardgames
9 Ludo Numeric P0010 2+ >4 1 All Boardgames
10 Other Numeric 1 All Boardgames