'Test the hand-computed example in factor.winsorize.'

def test_winsorize_hand_computed(self):

    f = self.f
    m = Mask()
    c = C()
    str_c = C(dtype=categorical_dtype, missing_value=None)
    factor_data = array([[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], [1.0, 8.0, 27.0, 64.0, 125.0, 216.0], [6.0, 5.0, 4.0, 3.0, 2.0, 1.0]])
    filter_data = array([[False, True, True, True, True, True], [True, False, True, True, True, True], [True, True, False, True, True, True]], dtype=bool)
    classifier_data = array([[1, 1, 1, 2, 2, 2], [1, 1, 1, 2, 2, 2], [1, 1, 1, 2, 2, 2]], dtype=int64_dtype)
    string_classifier_data = LabelArray(classifier_data.astype(str).astype(object), missing_value=None)
    terms = {'winsor_1': f.winsorize(min_percentile=0.33, max_percentile=0.67), 'winsor_2': f.winsorize(min_percentile=0.49, max_percentile=1), 'winsor_3': f.winsorize(min_percentile=0, max_percentile=0.67), 'masked': f.winsorize(min_percentile=0.33, max_percentile=0.67, mask=m), 'grouped': f.winsorize(min_percentile=0.34, max_percentile=0.66, groupby=c), 'grouped_str': f.winsorize(min_percentile=0.34, max_percentile=0.66, groupby=str_c), 'grouped_masked': f.winsorize(min_percentile=0.34, max_percentile=0.66, mask=m, groupby=c), 'grouped_masked_str': f.winsorize(min_percentile=0.34, max_percentile=0.66, mask=m, groupby=str_c)}
    expected = {'winsor_1': array([[2.0, 2.0, 3.0, 4.0, 5.0, 5.0], [8.0, 8.0, 27.0, 64.0, 125.0, 125.0], [5.0, 5.0, 4.0, 3.0, 2.0, 2.0]]), 'winsor_2': array([[3.0, 3.0, 3.0, 4.0, 5.0, 6.0], [27.0, 27.0, 27.0, 64.0, 125.0, 216.0], [6.0, 5.0, 4.0, 3.0, 3.0, 3.0]]), 'winsor_3': array([[1.0, 2.0, 3.0, 4.0, 5.0, 5.0], [1.0, 8.0, 27.0, 64.0, 125.0, 125.0], [5.0, 5.0, 4.0, 3.0, 2.0, 1.0]]), 'masked': array([[nan, 3.0, 3.0, 4.0, 5.0, 5.0], [27.0, nan, 27.0, 64.0, 125.0, 125.0], [5.0, 5.0, nan, 3.0, 2.0, 2.0]]), 'grouped': array([[2.0, 2.0, 2.0, 5.0, 5.0, 5.0], [8.0, 8.0, 8.0, 125.0, 125.0, 125.0], [5.0, 5.0, 5.0, 2.0, 2.0, 2.0]]), 'grouped_masked': array([[nan, 2.0, 3.0, 5.0, 5.0, 5.0], [1.0, nan, 27.0, 125.0, 125.0, 125.0], [6.0, 5.0, nan, 2.0, 2.0, 2.0]])}
    expected['grouped_str'] = expected['grouped']
    expected['grouped_masked_str'] = expected['grouped_masked']
    self.check_terms(terms, expected, initial_workspace={f: factor_data, c: classifier_data, str_c: string_classifier_data, m: filter_data}, mask=self.build_mask(self.ones_mask(shape=factor_data.shape)), check=partial(check_allclose, atol=0.001))
