scikit-learn-contrib/category_encoders

Error handling in inverse_transform is broken

クローズ

#190 opened on 2019/05/07

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)Python (397 件のフォーク)batch import
bughelp wanted

Repository metrics

Stars
 (2,322 個のスター)
PR merge metrics
 (平均マージ 4d 10h) (30d で 2 merged PRs)

説明

Inverse_transform should ideally handle absence of the columns dropped because of drop_invariant=True. But if it is not possible, inverse_transform() should at least return the correct error message instead of just crashing.

Example in form of a parameterized unit test:

    def test_inverse_wrong_feature_count_wit_drop_invariant(self):
        x = [['A', 'B', 'C'], ['D', 'E', 'C'], ['F', 'G', 'C']]  # the last column is constant 
        for encoder_name in {'BaseNEncoder', 'BinaryEncoder', 'OrdinalEncoder', 'OneHotEncoder'}:
            with self.subTest(encoder_name=encoder_name):
                enc = getattr(encoders, encoder_name)(drop_invariant=True)
                transformed = enc.fit_transform(x)

                # run inverse_transform() and check the raised exception text
                with self.assertRaises(ValueError) as cm:
                    enc.inverse_transform(transformed)
                self.assertTrue(str(cm.exception).startswith('Unexpected input dimension'))

コントリビューターガイド