'Tests for masking custom factors that compute a 1D out.'

def test_masked_single_column_output(self):

    start_date = self.pipeline_start_date
    end_date = self.pipeline_end_date
    alternating_mask = (AssetIDPlusDay() % 2).eq(0)
    cascading_mask = (AssetIDPlusDay() < (self.sids[(-1)] + start_date.day))
    alternating_mask.window_safe = True
    cascading_mask.window_safe = True
    for mask in (alternating_mask, cascading_mask):
        class SingleColumnOutput(CustomFactor, ):
            window_length = 1
            inputs = [self.col, mask]
            window_safe = True
            ndim = 1
            def compute(self, today, assets, out, col, mask):
                assert (out.shape == (1,))
                assert (col.shape == (1, mask.sum()))
                out[:] = col.sum()
        class UsesSingleColumnInput(CustomFactor, ):
            window_length = 1
            inputs = [self.col, mask, SingleColumnOutput(mask=mask)]
            def compute(self, today, assets, out, col, mask, single_column_output):
                assert (single_column_output.shape == (1, 1))
                single_column_output_value = single_column_output[0][0]
                expected_value = where(mask, col, 0).sum()
                assert (single_column_output_value == expected_value)
        columns = {'uses_single_column_input': UsesSingleColumnInput()}
        self.run_pipeline(Pipeline(columns=columns), start_date, end_date)
