Skip to content

Commit

Permalink
black 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoarbitrio committed Feb 1, 2024
1 parent 212682a commit 4718acf
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 55 deletions.
14 changes: 9 additions & 5 deletions src/cr/cube/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,15 @@ def counts_with_missings(self) -> np.ndarray:
return (
self._measures.weighted_valid_counts.raw_cube_array
if self._measures.weighted_valid_counts is not None
else self._measures.unweighted_valid_counts.raw_cube_array
if self._measures.unweighted_valid_counts is not None
else self._measures.weighted_counts.raw_cube_array
if self.has_weighted_counts
else self._measures.unweighted_counts.raw_cube_array
else (
self._measures.unweighted_valid_counts.raw_cube_array
if self._measures.unweighted_valid_counts is not None
else (
self._measures.weighted_counts.raw_cube_array
if self.has_weighted_counts
else self._measures.unweighted_counts.raw_cube_array
)
)
)

@lazyproperty
Expand Down
10 changes: 6 additions & 4 deletions src/cr/cube/cubepart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1736,10 +1736,12 @@ def _assemble_vector(self, base_vector, subtotals, order, diffs_nan=False):
# values from a _BaseSubtotals subclass.
vector_subtotals = np.array(
[
np.nan
if diffs_nan and len(subtotal.subtrahend_idxs) > 0
else np.sum(base_vector[subtotal.addend_idxs])
- np.sum(base_vector[subtotal.subtrahend_idxs])
(
np.nan
if diffs_nan and len(subtotal.subtrahend_idxs) > 0
else np.sum(base_vector[subtotal.addend_idxs])
- np.sum(base_vector[subtotal.subtrahend_idxs])
)
for subtotal in subtotals
]
)
Expand Down
8 changes: 5 additions & 3 deletions src/cr/cube/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,11 @@ def _replaced_element_transforms(self, element_transforms) -> Dict:
if key == "subvar_id":
# --- translate from subvariable id
new_keys = tuple(
self._subvar_aliases[self._subvar_ids.index(_id)]
if _id in self._subvar_ids
else None
(
self._subvar_aliases[self._subvar_ids.index(_id)]
if _id in self._subvar_ids
else None
)
for _id in old_keys
)
else:
Expand Down
27 changes: 18 additions & 9 deletions src/cr/cube/matrix/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,24 @@ def row_display_order(cls, dimensions, second_order_measures, format):
HelperCls = (
_SortRowsByBaseColumnHelper
if collation_method == CM.OPPOSING_ELEMENT
else _SortRowsByDerivedColumnHelper
if collation_method == CM.OPPOSING_INSERTION and dim_type in DT.ARRAY_TYPES
else _SortRowsByInsertedColumnHelper
if collation_method == CM.OPPOSING_INSERTION
else _SortRowsByLabelHelper
if collation_method == CM.LABEL
else _SortRowsByMarginalHelper
if collation_method == CM.MARGINAL
else _RowOrderHelper
else (
_SortRowsByDerivedColumnHelper
if collation_method == CM.OPPOSING_INSERTION
and dim_type in DT.ARRAY_TYPES
else (
_SortRowsByInsertedColumnHelper
if collation_method == CM.OPPOSING_INSERTION
else (
_SortRowsByLabelHelper
if collation_method == CM.LABEL
else (
_SortRowsByMarginalHelper
if collation_method == CM.MARGINAL
else _RowOrderHelper
)
)
)
)
)
return HelperCls(dimensions, second_order_measures, format)._display_order

Expand Down
64 changes: 39 additions & 25 deletions src/cr/cube/matrix/cubemeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ def factory(cls, counts, diff_nans, cube, dimensions, slice_idx):
Chooses between unweighted and weighted counts based on `type`.
"""
dimension_type_strings = tuple(
"MR"
if dim_type == DT.MR
else "ARR"
if dim_type in DT.ARRAY_TYPES
else "CAT"
(
"MR"
if dim_type == DT.MR
else "ARR" if dim_type in DT.ARRAY_TYPES else "CAT"
)
for dim_type in cube.dimension_types[-2:]
)
CubeCountsCls = {
Expand Down Expand Up @@ -812,11 +812,15 @@ def factory(cls, cube, dimensions, slice_idx):
CubeMeansCls = (
_MrXMrCubeMeans
if dimension_types == (DT.MR, DT.MR)
else _MrXCatCubeMeans
if dimension_types[0] == DT.MR
else _CatXMrCubeMeans
if dimension_types[1] == DT.MR
else _CatXCatCubeMeans
else (
_MrXCatCubeMeans
if dimension_types[0] == DT.MR
else (
_CatXMrCubeMeans
if dimension_types[1] == DT.MR
else _CatXCatCubeMeans
)
)
)
return CubeMeansCls(
dimensions, cube.means[cls._slice_idx_expr(cube, slice_idx)]
Expand Down Expand Up @@ -1027,11 +1031,15 @@ def factory(cls, cube, dimensions, slice_idx):
CubeSumsCls = (
_MrXMrCubeStdDev
if dimension_types == (DT.MR, DT.MR)
else _MrXCatCubeStdDev
if dimension_types[0] == DT.MR
else _CatXMrCubeStdDev
if dimension_types[1] == DT.MR
else _CatXCatCubeStdDev
else (
_MrXCatCubeStdDev
if dimension_types[0] == DT.MR
else (
_CatXMrCubeStdDev
if dimension_types[1] == DT.MR
else _CatXCatCubeStdDev
)
)
)
return CubeSumsCls(
dimensions, cube.stddev[cls._slice_idx_expr(cube, slice_idx)]
Expand Down Expand Up @@ -1110,11 +1118,13 @@ def factory(cls, cube, dimensions, slice_idx):
CubeSumsCls = (
_MrXMrCubeSums
if dimension_types == (DT.MR, DT.MR)
else _MrXCatCubeSums
if dimension_types[0] == DT.MR
else _CatXMrCubeSums
if dimension_types[1] == DT.MR
else _CatXCatCubeSums
else (
_MrXCatCubeSums
if dimension_types[0] == DT.MR
else (
_CatXMrCubeSums if dimension_types[1] == DT.MR else _CatXCatCubeSums
)
)
)
return CubeSumsCls(dimensions, cube.sums[cls._slice_idx_expr(cube, slice_idx)])

Expand Down Expand Up @@ -1202,11 +1212,15 @@ def factory(cls, cube, dimensions, slice_idx):
UnconditionalCubeCountsCls = (
_MrXMrUnconditionalCubeCounts
if dimension_types == (DT.MR, DT.MR)
else _MrXCatUnconditionalCubeCounts
if dimension_types[0] == DT.MR
else _CatXMrUnconditionalCubeCounts
if dimension_types[1] == DT.MR
else _CatXCatUnconditionalCubeCounts
else (
_MrXCatUnconditionalCubeCounts
if dimension_types[0] == DT.MR
else (
_CatXMrUnconditionalCubeCounts
if dimension_types[1] == DT.MR
else _CatXCatUnconditionalCubeCounts
)
)
)
return UnconditionalCubeCountsCls(
dimensions,
Expand Down
16 changes: 10 additions & 6 deletions src/cr/cube/matrix/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,9 +1712,11 @@ def blocks(self):
return (
self._second_order_measures.row_proportions.blocks
if self._dimensions[-2].dimension_type == DT.CAT_DATE
else self._second_order_measures.column_proportions.blocks
if self._dimensions[-1].dimension_type == DT.CAT_DATE
else self._second_order_measures.table_proportions.blocks
else (
self._second_order_measures.column_proportions.blocks
if self._dimensions[-1].dimension_type == DT.CAT_DATE
else self._second_order_measures.table_proportions.blocks
)
)


Expand Down Expand Up @@ -1744,9 +1746,11 @@ def blocks(self):
return (
self._second_order_measures.row_std_err.blocks
if self._dimensions[-2].dimension_type == DT.CAT_DATE
else self._second_order_measures.column_std_err.blocks
if self._dimensions[-1].dimension_type == DT.CAT_DATE
else self._second_order_measures.table_std_err.blocks
else (
self._second_order_measures.column_std_err.blocks
if self._dimensions[-1].dimension_type == DT.CAT_DATE
else self._second_order_measures.table_std_err.blocks
)
)


Expand Down
8 changes: 5 additions & 3 deletions src/cr/cube/stripe/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def display_order(cls, rows_dimension, measures, format):
HelperCls = (
_SortByMeasureHelper
if order_spec.collation_method == CM.UNIVARIATE_MEASURE
else _SortByLabelHelper
if order_spec.collation_method == CM.LABEL
else _OrderHelper
else (
_SortByLabelHelper
if order_spec.collation_method == CM.LABEL
else _OrderHelper
)
)
return HelperCls(rows_dimension, measures, format)._display_order

Expand Down

0 comments on commit 4718acf

Please sign in to comment.