fix: two CellService bugs — multi-hierarchy dict overwrite and missing kwargs#1421
fix: two CellService bugs — multi-hierarchy dict overwrite and missing kwargs#1421kaizeenn wants to merge 2 commits into
Conversation
…g kwargs Fix cubewise-code#1068: clear_with_dataframe overwrites mdx_selections[dimension] on each iteration when dimension_mapping maps a dimension to a list of hierarchies, so only the last hierarchy appears in the generated MDX. Replace the overwriting loop with a MdxHierarchySet.union() accumulation so every hierarchy contributes to the MDX crossjoin. Fix cubewise-code#1113: execute_mdx_dataframe_pivot has no **kwargs parameter, so callers cannot pass arguments like cell_properties=["FormattedValue"] or use_compact_json=True that extract_cellset_dataframe_pivot accepts. Add **kwargs to the signature and forward it to extract_cellset_dataframe_pivot. Also fix a minor error-message bug on the same line (cubewise-code#1068 report): the ValueError for a non-str dimension_mapping value referred to the loop variable 'dimension' instead of the DataFrame column variable 'column'. Add Tests/test_cellservice_unit.py with 6 unit tests that run without a live TM1 server, covering both fixes. Signed-off-by: kaizeenn <khairil0153@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes two long-standing CellService issues: (1) clear_with_dataframe incorrectly overwrote MDX selections when a dimension was mapped to multiple hierarchies, and (2) execute_mdx_dataframe_pivot did not accept/forward keyword arguments needed by downstream extraction helpers.
Changes:
- Update
clear_with_dataframeto accumulate multiple hierarchy selections viaMdxHierarchySet.union()so all hierarchies contribute to the MDX (issue #1068), and fix the related error message to reference the correct key (column). - Update
execute_mdx_dataframe_pivotto accept**kwargsand forward them toextract_cellset_dataframe_pivot(issue #1113). - Add unit tests covering both regressions without requiring a live TM1 server.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| TM1py/Services/CellService.py | Fixes multi-hierarchy handling in clear_with_dataframe and forwards **kwargs in execute_mdx_dataframe_pivot. |
| Tests/test_cellservice_unit.py | Adds regression tests for multi-hierarchy MDX generation and kwargs forwarding. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """ | ||
|
|
||
| import unittest | ||
| from unittest.mock import MagicMock, patch, call |
|
Tests completed for environment: tm1-11. Check artifacts for details. |
1 similar comment
|
Tests completed for environment: tm1-11. Check artifacts for details. |
|
Thank you @kaizeenn Please consider the feedback from Copilot. It identified 2 unused imports. |
|
Hi @MariusWirtz, I've updated the PR! I removed the 2 unused imports from the unit tests, and I've also added two live integration regression tests in |
Summary
Fixes two bugs in
CellService.pythat have been open for a while.Fix #1068 —
clear_with_dataframeoverwrites hierarchiesRoot cause: When
dimension_mappingmaps a dimension to a list of hierarchies, the loop at line ~776 does:Each iteration overwrites the same dict key, so only the last hierarchy survives and the generated MDX is wrong.
Fix: Accumulate a
MdxHierarchySet.union()across all hierarchies so every one contributes to the MDX crossjoin:Also fixed a minor error-message bug on the same line (reported in the same issue): the
ValueErrorfor a non-str mapping value referenced loop variabledimensioninstead of the DataFrame column variablecolumn.Fix #1113 —
execute_mdx_dataframe_pivotswallows kwargsRoot cause: The method signature had no
**kwargs, so calling it with e.g.cell_properties=["FormattedValue"]oruse_compact_json=TrueraisedTypeErroreven thoughextract_cellset_dataframe_pivotaccepts those arguments.Fix: Add
**kwargsto the signature and forward it:Tests
Added
Tests/test_cellservice_unit.py— 6 unit tests that run without a live TM1 server (mocking the REST layer and cube service):**kwargsforwarded correctly toextract_cellset_dataframe_pivotcell_propertiesforwardedAll 6 pass.