fix: two CellService bugs — multi-hierarchy dict overwrite and missing kwargs#1421
Open
kaizeenn wants to merge 1 commit into
Open
fix: two CellService bugs — multi-hierarchy dict overwrite and missing kwargs#1421kaizeenn wants to merge 1 commit into
kaizeenn wants to merge 1 commit 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>
Contributor
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.