Example #1
0
    def test_capping_values_both_null_error(self):
        """Test that an exception is raised if both capping_values are null."""

        x = CappingTransformer(capping_values={"a": [1, 3], "b": [None, -1]})

        with pytest.raises(ValueError, match="both values are None for key a"):

            x.check_capping_values_dict(
                capping_values_dict={"a": [None, None], "b": [None, 1]}, dict_name="eee"
            )
Example #2
0
    def test_lower_value_gte_upper_value_error(self):
        """Test that an exception is raised if capping_values_dict[0] >= capping_values_dict[1]."""

        x = CappingTransformer(capping_values={"a": [1, 2], "b": [None, -1]})

        with pytest.raises(
            ValueError,
            match="lower value is greater than or equal to upper value for key a",
        ):

            x.check_capping_values_dict(
                capping_values_dict={"a": [4, 3], "b": [None, -1]}, dict_name="eee"
            )
Example #3
0
    def test_capping_value_nan_inf_error(self, value):
        """Test that an exception is raised if capping_values are np.nan or np.inf values."""

        x = CappingTransformer(capping_values={"a": [1, 3], "b": [None, 1]})

        with pytest.raises(
            ValueError,
            match="item in eee lists contains numpy NaN or Inf values",
        ):

            x.check_capping_values_dict(
                capping_values_dict={"b": [1, 3], "a": [None, value]}, dict_name="eee"
            )
Example #4
0
    def test_capping_values_non_numeric_error(self):
        """Test that an exception is raised if capping_values_dict contains any non-nulls and non-numeric values."""

        x = CappingTransformer(capping_values={"a": [1, 3], "b": [None, -1]})

        with pytest.raises(
            TypeError,
            match=r"each item in eee lists must contain numeric values or None, got \<class 'str'\> for key a",
        ):

            x.check_capping_values_dict(
                capping_values_dict={"b": [1, 3], "a": [None, "a"]}, dict_name="eee"
            )
Example #5
0
    def test_capping_values_non_length_2_list_item_error(self):
        """Test that an exception is raised if capping_values_dict has any non length 2 list items."""

        x = CappingTransformer(capping_values={"a": [1, 3], "b": [None, -1]})

        with pytest.raises(
            ValueError,
            match="each item in ddd should be length 2, but got 1 for key b",
        ):

            x.check_capping_values_dict(
                capping_values_dict={"a": [1, 3], "b": [None]}, dict_name="ddd"
            )
Example #6
0
    def test_capping_values_non_list_item_error(self):
        """Test that an exception is raised if capping_values_dict has any non list items."""

        x = CappingTransformer(capping_values={"a": [1, 3], "b": [None, -1]})

        with pytest.raises(
            TypeError,
            match=r"each item in ccc should be a list, but got \<class 'tuple'\> for key b",
        ):

            x.check_capping_values_dict(
                capping_values_dict={"a": [1, 3], "b": (None, -1)}, dict_name="ccc"
            )
Example #7
0
    def test_capping_values_non_str_key_error(self):
        """Test that an exception is raised if capping_values_dict has any non str keys."""

        x = CappingTransformer(capping_values={"a": [1, 3], "b": [None, -1]})

        with pytest.raises(
            TypeError,
            match=r"all keys in bbb should be str, but got \<class 'int'\>",
        ):

            x.check_capping_values_dict(
                capping_values_dict={"a": [1, 3], 1: [None, -1]}, dict_name="bbb"
            )
Example #8
0
    def test_capping_values_not_dict_error(self):
        """Test that an exception is raised if capping_values_dict is not a dict."""

        x = CappingTransformer(capping_values={"a": [1, 3], "b": [None, -1]})

        with pytest.raises(
            TypeError,
            match="aaa should be dict of columns and capping values",
        ):

            x.check_capping_values_dict(
                capping_values_dict=("a", [1, 3], "b", [None, -1]), dict_name="aaa"
            )