Exemple #1
0
    def test__get_univariate_error(self):
        """If something else is passed, rasie a TypeError."""
        distribution = 123
        ct = GaussianCopulaTransformer(distribution=distribution)

        with pytest.raises(TypeError):
            ct._get_univariate()
Exemple #2
0
    def test__get_univariate_class(self):
        """If a class is passed, create an instance without args."""
        distribution = copulas.univariate.Univariate
        ct = GaussianCopulaTransformer(distribution=distribution)

        univariate = ct._get_univariate()

        assert isinstance(univariate, copulas.univariate.Univariate)
Exemple #3
0
    def test__get_univariate_instance(self):
        """If a univariate instance is passed, make a copy."""
        distribution = copulas.univariate.Univariate()
        ct = GaussianCopulaTransformer(distribution=distribution)

        univariate = ct._get_univariate()

        assert univariate is not distribution
        assert isinstance(univariate, copulas.univariate.Univariate)
        assert dir(univariate) == dir(distribution)
Exemple #4
0
    def test_int_nan(self):
        data = np.array([1, 2, 1, 2, 1, np.nan])

        ct = GaussianCopulaTransformer(dtype=int)
        transformed = ct.fit_transform(data)

        assert isinstance(transformed, np.ndarray)
        assert transformed.shape == (6, 2)

        reverse = ct.reverse_transform(transformed)
        np.testing.assert_array_almost_equal(reverse, data, decimal=2)
Exemple #5
0
    def test_int(self):
        data = np.array([1, 2, 1, 2, 1])

        ct = GaussianCopulaTransformer(dtype=int)
        transformed = ct.fit_transform(data)

        assert isinstance(transformed, np.ndarray)
        assert transformed.shape == (5, )

        reverse = ct.reverse_transform(transformed)
        assert list(reverse) == [1, 2, 1, 2, 1]
Exemple #6
0
    def test__get_univariate_tuple(self):
        """If a tuple is passed, create an instance using the given args."""
        distribution = (copulas.univariate.Univariate, {
            'candidates': 'a_candidates_list'
        })
        ct = GaussianCopulaTransformer(distribution=distribution)

        univariate = ct._get_univariate()

        assert isinstance(univariate, copulas.univariate.Univariate)
        assert univariate.candidates == 'a_candidates_list'
Exemple #7
0
    def test_not_null_column(self):
        data = np.array([1, 2, 1, 2, np.nan, 1])

        ct = GaussianCopulaTransformer(null_column=False)
        transformed = ct.fit_transform(data)

        assert isinstance(transformed, np.ndarray)
        assert transformed.shape == (6, )

        reverse = ct.reverse_transform(transformed)

        np.testing.assert_array_almost_equal(reverse, data, decimal=2)
Exemple #8
0
    def test_stats(self):
        data = np.random.normal(loc=4, scale=4, size=1000)

        ct = GaussianCopulaTransformer()
        transformed = ct.fit_transform(data)

        assert isinstance(transformed, np.ndarray)
        assert transformed.shape == (1000, )

        np.testing.assert_almost_equal(transformed.mean(), 0, decimal=1)
        np.testing.assert_almost_equal(transformed.std(), 1, decimal=1)

        reverse = ct.reverse_transform(transformed)

        np.testing.assert_array_almost_equal(reverse, data, decimal=1)
Exemple #9
0
    def test___init__super_attrs(self):
        """super() arguments are properly passed and set as attributes."""
        ct = GaussianCopulaTransformer(dtype='int', nan='mode', null_column=False)

        assert ct.dtype == 'int'
        assert ct.nan == 'mode'
        assert ct.null_column is False
Exemple #10
0
    def test___init__non_distr(self):
        """If distribution is not an str, it is store as given."""
        univariate = copulas.univariate.Univariate()
        ct = GaussianCopulaTransformer(distribution=univariate)

        assert ct._distribution is univariate
Exemple #11
0
    def test___init__str_distr(self):
        """If distribution is an str, it is resolved using the _DISTRIBUTIONS dict."""
        ct = GaussianCopulaTransformer(distribution='univariate')

        assert ct._distribution is copulas.univariate.Univariate