Skip to content

Commit

Permalink
Fix scale means for CA as 0th
Browse files Browse the repository at this point in the history
* For a slice that's a Categorical Array, if it's to be treated as the
0th cube in a Tabbook, we need to check if it actually has scale means
on it's column dimension (and not the 0th categorical one, because there
aren't any)
* Change the unit tests accordingly
  • Loading branch information
slobodan-ilic committed Jan 23, 2019
1 parent b213ed3 commit 24d5856
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/cr/cube/cube_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ def scale_means(self, hs_dims=None, prune=False):
scaled mean (as numpy array). If both row and col scaled means are
present, return them as two numpy arrays inside of a list.
"""
scale_means = self._cube.scale_means(hs_dims, prune)
if self.ca_as_0th:
return [None, None]
return [scale_means[0][-1][self._index]]
return self._cube.scale_means(hs_dims, prune)[self._index]

@memoize
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_cube_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,10 @@ def test_scale_means_for_ca_as_0th(self):
"""Test that CA as 0th slice always returns empty scale means."""
cube = Mock()
cube.dim_types = (DT.CA_SUBVAR,)
scale_means_value = Mock()
cube.scale_means.return_value = [[None, [scale_means_value, Mock(), Mock()]]]
cs = CubeSlice(cube, 0, ca_as_0th=True)
assert cs.scale_means() == [None, None]
assert cs.scale_means() == [scale_means_value]

def test_shape_property_deprecated(self):
cube = Mock()
Expand Down

0 comments on commit 24d5856

Please sign in to comment.