Exemplo n.º 1
0
    def it_can_compute_a_subtotal_intersection_value(
        self,
        request,
        row_add_idxs,
        row_sub_idxs,
        col_add_idxs,
        col_sub_idxs,
        diff_cols_nan,
        diff_rows_nan,
        expected_value,
    ):
        col_subtotal_ = instance_mock(
            request,
            _Subtotal,
            addend_idxs=col_add_idxs,
            subtrahend_idxs=col_sub_idxs,
        )
        row_subtotal_ = instance_mock(
            request,
            _Subtotal,
            addend_idxs=row_add_idxs,
            subtrahend_idxs=row_sub_idxs,
        )
        base_values = np.arange(12).reshape(3, 4)
        subtotals = SumSubtotals(base_values, None, diff_cols_nan,
                                 diff_rows_nan)

        np.testing.assert_equal(
            subtotals._intersection(row_subtotal_, col_subtotal_),
            expected_value)
Exemplo n.º 2
0
    def it_can_compute_a_subtotal_row_to_help(self, subtotal_, addend_idxs,
                                              subtrahend_idxs, diff_rows_nan,
                                              expected_value):
        subtotal_.addend_idxs = addend_idxs
        subtotal_.subtrahend_idxs = subtrahend_idxs
        base_values = np.arange(12).reshape(3, 4)
        subtotals = SumSubtotals(base_values,
                                 None,
                                 diff_rows_nan=diff_rows_nan)

        assert subtotals._subtotal_row(subtotal_).tolist() == pytest.approx(
            expected_value, nan_ok=True)
Exemplo n.º 3
0
    def rows_margin_proportion(self):
        """1D/2D np.float64 ndarray of weighted-proportion for each slice row/cell."""
        # --- an X_MR slice produces a 2D rows-margin (each cell has its own N) ---
        # --- TODO: Should rows_margin_proportion only be defined when it's 1D? This would
        # --- require changes to exporter to use the bases to give a "rows_margin_range"
        if not self._measures.rows_table_proportion.is_defined:
            return self._assemble_matrix(
                SumSubtotals.blocks(
                    self.rows_margin / self.table_weighted_bases,
                    self._dimensions,
                )
            )

        # --- otherwise rows-margin is a vector ---
        return self._assemble_marginal(self._measures.rows_table_proportion)
Exemplo n.º 4
0
    def it_provides_a_subtotal_rows_interface_method(self, request,
                                                     dimensions_, _init_):
        base_values = [[4, 1], [3, 5]]
        property_mock(
            request,
            SumSubtotals,
            "_subtotal_rows",
            return_value=np.array([[4, 3], [2, 1]]),
        )

        subtotal_rows = SumSubtotals.subtotal_rows(base_values, dimensions_)

        _init_.assert_called_once_with(ANY, [[4, 1], [3, 5]], dimensions_,
                                       False, False)
        assert subtotal_rows.tolist() == [[4, 3], [2, 1]]
Exemplo n.º 5
0
    def it_provides_an_intersections_interface_method(self, request,
                                                      dimensions_, _init_):
        base_values = [[1, 5], [8, 0]]
        property_mock(
            request,
            SumSubtotals,
            "_intersections",
            return_value=np.array([[1, 2], [3, 4]]),
        )

        intersections = SumSubtotals.intersections(base_values, dimensions_)

        _init_.assert_called_once_with(ANY, [[1, 5], [8, 0]], dimensions_,
                                       False, False)
        assert intersections.tolist() == [[1, 2], [3, 4]]
Exemplo n.º 6
0
    def columns_margin_proportion(self):
        """1D/2D np.float64 ndarray of weighted-prop for each column of this slice."""
        # --- an MR_X slice produces a 2D columns-margin (each cell has its own N) ---
        # --- TODO: Should colums_margin_proportion only be defined when it's 1D? This
        # --- requires changes to exporter to use the bases to give a
        # --- "columns_margin_range"
        if not self._measures.columns_table_proportion.is_defined:
            return self._assemble_matrix(
                SumSubtotals.blocks(
                    self.columns_margin / self.table_weighted_bases,
                    self._dimensions,
                )
            )

        # --- otherwise columns-margin-proportion is a maginal ---
        return self._assemble_marginal(self._measures.columns_table_proportion)
Exemplo n.º 7
0
    def it_provides_a_subtotal_columns_interface_method(
            self, request, dimensions_, _init_):
        base_values = [[0, 4], [7, 9]]
        property_mock(
            request,
            SumSubtotals,
            "_subtotal_columns",
            return_value=np.array([[1, 2], [3, 4]]),
        )

        subtotal_columns = SumSubtotals.subtotal_columns(
            base_values, dimensions_)

        _init_.assert_called_once_with(ANY, [[0, 4], [7, 9]], dimensions_,
                                       False, False)
        assert subtotal_columns.tolist() == [[1, 2], [3, 4]]