Skip to content

Commit

Permalink
fix: Python3, Black, and numpy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
scanny committed Nov 9, 2020
1 parent e3410e6 commit 04e382f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
42 changes: 31 additions & 11 deletions src/cr/cube/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, unordered_matrix):

@classmethod
def matrix(cls, cube, dimensions, slice_idx):
"""-> TransformedMatrix object constructed from values of `cube`.
"""Return TransformedMatrix object constructed from values of `cube`.
`cube` is the `cr.cube.Cube` object containing the data for this matrix. Note
that not all the data in `cube` will necessarily be used by this matrix. When
Expand Down Expand Up @@ -280,7 +280,7 @@ def _columns_dimension(self):

@lazyproperty
def _inserted_columns(self):
"""-> tuple of _InsertedColumn objects representing subtotal columns.
"""tuple of _InsertedColumn objects representing subtotal columns.
The returned vectors are in the order subtotals were specified in the cube
result, which is no particular order. All subtotals defined on the column
Expand Down Expand Up @@ -308,7 +308,7 @@ def _inserted_columns(self):

@lazyproperty
def _inserted_rows(self):
"""-> tuple of _InsertedRow objects representing inserted subtotal rows.
"""tuple of _InsertedRow objects representing inserted subtotal rows.
The returned vectors are in the order subtotals were specified in the cube
result, which is no particular order.
Expand All @@ -331,7 +331,7 @@ def _inserted_rows(self):

@lazyproperty
def _row_order(self):
""" -> 1D ndarray of int row idx specifying order of unordered-array rows."""
"""1D ndarray of int row idx specifying order of unordered-array rows."""
dimension = self._rows_dimension
collation_method = dimension.collation_method

Expand Down Expand Up @@ -436,7 +436,7 @@ def table_margin(self):
) # pragma: no cover

def _array_type_std_res(self, counts, total, colsum, rowsum):
"""-> 2D ndarray of np.float64 std-res value for each cell of MR matrix.
"""Return 2D np.float64 ndarray of std-res value for each cell of MR matrix.
This is a utility method used by a matrix with one or more MR dimensions. The
caller forms the input arrays based on which of its dimensions are MR.
Expand Down Expand Up @@ -1963,7 +1963,17 @@ def base(self):
because each MR_SUBVAR element has a distinct unweighted N. A vector opposing
a CAT dimension produces a scalar value.
"""
return self._unassembled_vector.base
unassembled_base = self._unassembled_vector.base

# --- `base` is an ndarray when opposing dimension is MR or CA_SUBVAR.
# --- Neither of these can have subtotals (subvars don't add), so no
# --- interleaving is necessary.
if isinstance(unassembled_base, np.ndarray):
return unassembled_base[self._opposing_order]

# --- otherwise it's a scalar value and neither interleaving nor ordering
# --- is required
return unassembled_base

@lazyproperty
def column_index(self):
Expand All @@ -1973,7 +1983,7 @@ def column_index(self):
"""

def fsubtot(inserted_vector):
"""-> np.nan as unconditional col-index value for `inserted_vector`.
"""Return np.nan as unconditional col-index value for `inserted_vector`.
Called by ._apply_interleaved() to compute inserted value which it places
in the right vector position.
Expand Down Expand Up @@ -2035,7 +2045,17 @@ def margin(self):
dimension produces a scalar value. Values are np.int64 if the cube-result is
unweighted.
"""
return self._unassembled_vector.margin
unassembled_margin = self._unassembled_vector.margin

# --- `margin` is an ndarray when opposing dimension is MR or CA_SUBVAR.
# --- Neither of these can have subtotals (subvars don't add), so no
# --- interleaving is necessary.
if isinstance(unassembled_margin, np.ndarray):
return unassembled_margin[self._opposing_order]

# --- otherwise it's a scalar value and neither interleaving nor ordering
# --- is required
return unassembled_margin

@lazyproperty
def means(self):
Expand All @@ -2045,7 +2065,7 @@ def means(self):
"""

def fsubtot(inserted_vector):
"""-> np.nan as unconditional mean value for `inserted_vector`.
"""Return np.nan as unconditional mean value for `inserted_vector`.
Passed to and called by ._apply_interleaved() to compute inserted value
which it places in the right vector position.
Expand Down Expand Up @@ -2157,7 +2177,7 @@ def zscores(self):
"""

def fsubtot(inserted_vector):
"""-> np.float64 zscore for `inserted_vector`.
"""Return np.float64 zscore for `inserted_vector`.
Passed to and called by ._apply_interleaved() to compute inserted value
which it places in the right vector position.
Expand Down Expand Up @@ -2187,7 +2207,7 @@ def fsubtot(inserted_vector):
return self._apply_interleaved(self._unassembled_vector.zscores, fsubtot)

def _apply_interleaved(self, unassembled_values, fsubtot):
"""-> 1D array of result of applying fbase or fsubtot to each interleaved item.
"""Return 1D array result of applying fbase or fsubtot to each interleaved item.
`unassembled_values` is the "unassembled" vector measure values. This vector can
be a base vector or an inserted vector.
Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_cubepart.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ def it_places_insertions_on_a_reordered_dimension_in_the_right_position(self):
],
)

@pytest.mark.xfail(reason="WIP", raises=AssertionError, strict=True)
def it_provides_same_proportions_without_explicit_order(self):
transforms = TR.TEST_DASHBOARD_TRANSFORM_SINGLE_EL_VISIBLE
slice_ = Cube(CR.TEST_DASHBOARD_FIXTURE, transforms=transforms).partitions[0]
Expand Down

0 comments on commit 04e382f

Please sign in to comment.