Open MariusWirtz opened 3 weeks ago
Sounds good Marius, that will benefit me too.
Related to the suggested features: perhaps an option to have one dimension's elements on the columns would be nice to much like execute_mdx_dataframe_shaped
. That would save people a melt.
E.g. Sales Cube below
Version | Product | Sales Value | Sales Quantity | Sales Price |
---|---|---|---|---|
ACT | 123 | 320.4 | 10 | 32.4 |
ACT | 123 | 32.32 | 8 | 4.04 |
ACT | 123 | 10.3 | 1 | 10.3 |
You currently have to share it yourself like this (unless I missed any current feature):
Version | Product | Sales Measure | Value |
---|---|---|---|
ACT | 123 | Sales Value | 320.4 |
ACT | 123 | Sales Quantity | 10 |
ACT | 123 | Sales Price | 32.4 |
ACT | 123 | ... | ... |
A few ideas to realize this:
with argument column_dimension
we melt the df with:
id_vars = [col for col in columns if col in dimensions]
, var_name=column_dimension
.value_vars =[col for col in columns if col not in dimensions]
. with the argument shaped=True
the column_dimension
will be inferred? var_name = [dim for dim in dimensions if dim not in columns][0]
<- with an exception if you end up with len([dim for dim in dimensions if dim not in columns][0]) != 1
allow to pass the melt parameters to write_dataframe
.
Currently, the
write_dataframe
function expects the data frame columns to match the dimension order perfectly in the cube. For example, for a cube with five dimensions (Version, Time, Period, Product, Measure), the function expects a data frame with six columns (Version, Time, Period, Product, Measure, Value) in the correct order.It would be convenient if TM1py could order the columns itself, and the user would not need to ensure the column order. That approach would also allow to pass
contexts
/fixed elements
to be handled more efficiently. They could be passed as a dictionary, e.g.,{'Version': 'Actual'}.
When these new arguments are used, the column header must match the dimension name so that TM1py can order accordingly.