Skip to content

Commit 59d7266

Browse files
fix _replaced_order_element_ids to avoid None returns
1 parent da0d3a4 commit 59d7266

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/cr/cube/dimension.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Dimensions(tuple):
6363
"""Collection containing every dimension defined in cube response."""
6464

6565
def __repr__(self) -> str:
66-
"str representation of this dimension sequence." ""
66+
"""str representation of this dimension sequence."""
6767
dim_lines = "\n".join(str(d) for d in self)
6868
return f"Dimensions:\n{dim_lines}"
6969

@@ -875,7 +875,12 @@ def _replaced_order_element_ids(self, element_ids) -> List[Optional[str]]:
875875
The explicit order transform includes a list of ids that can be specified in
876876
many different ways, this translate them to the subvariable aliases.
877877
"""
878-
return [self.translate_element_id(_id) for _id in element_ids]
878+
return list(
879+
filter(
880+
lambda v: v is not None,
881+
[self.translate_element_id(_id) for _id in element_ids],
882+
)
883+
)
879884

880885
@lazyproperty
881886
def _subvar_aliases(self) -> Tuple[str, ...]:

tests/integration/test_cubepart.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,31 @@
2222
class Test_Slice:
2323
"""Integration-test suite for _Slice object."""
2424

25+
def test_it_provides_values_for_cat_x_mr_x_mr_with_odd_order(self):
26+
transf = {
27+
"columns_dimension": {
28+
"elements": {
29+
"2": {"hide": True},
30+
"3": {"hide": True},
31+
"4": {"hide": True},
32+
"foo": {"hide": True},
33+
"bar": {"hide": True},
34+
},
35+
"order": {
36+
"element_ids": [1, 2, 3, 4, 6, "foo", "bar"],
37+
"type": "explicit",
38+
},
39+
},
40+
}
41+
parts = Cube(CR.CAT_X_MR_X_MR, transforms=transf, population=9001).partitions
42+
assert len(parts) == 2
43+
assert parts[0].column_proportions == pytest.approx(
44+
np.array([[0.60553814], [0.10292581], [0.10031348]])
45+
)
46+
assert parts[1].column_proportions == pytest.approx(
47+
np.array([[0.08141321], [0.60522273], [0.5847414]])
48+
)
49+
2550
def test_it_provides_values_for_cat_x_cat(self):
2651
slice_ = Cube(CR.CAT_X_CAT, population=9001).partitions[0]
2752

0 commit comments

Comments
 (0)