示例#1
0
文件: test_base.py 项目: csala/SDV
    def test_fit_trains_column_model(self, ht_mock, gm_mock):
        """Test the ``Constraint.fit`` method trains the column model.

        When ``fit_columns_model`` is True and there are multiple ``constraint_columns``,
        the ``Constraint.fit`` method is expected to:
        - Call ``_fit`` method.
        - Create ``_hyper_transformer``.
        - Create ``_column_model`` and train it.

        Input:
        - Table data (pandas.DataFrame)
        """
        # Setup
        table_data = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
        instance = Constraint(handling_strategy='transform',
                              fit_columns_model=True)
        instance.constraint_columns = ('a', 'b')

        # Run
        instance.fit(table_data)

        # Assert
        gm_mock.return_value.fit.assert_called_once()
        calls = ht_mock.return_value.fit_transform.mock_calls
        args = calls[0][1]
        assert len(calls) == 1
        pd.testing.assert_frame_equal(args[0], table_data)
示例#2
0
    def test_fit(self):
        """Test the ``Constraint.fit`` method.

        The ``Constraint.fit`` method is a no-op method, so nothing needs to happen. We just call
        the method to certify that the interface is right.

        Input:
        - Table data (pandas.DataFrame)
        """
        # Setup
        table_data = pd.DataFrame({'a': [1, 2, 3]})

        # Run
        instance = Constraint(handling_strategy='transform')
        instance.fit(table_data)
示例#3
0
文件: test_base.py 项目: csala/SDV
    def test_fit_gaussian_multivariate_correct_distribution(self, gm_mock):
        """Test the ``GaussianMultivariate`` from the ``Constraint.fit`` method.

        The ``GaussianMultivariate`` is expected to be called with default distribution
        set as ``GaussianUnivariate``.

        Input:
        - Table data (pandas.DataFrame)
        """
        # Setup
        table_data = pd.DataFrame({'a': [1, 2, 3], 'b': [1, 2, 3]})
        instance = Constraint(handling_strategy='transform',
                              fit_columns_model=True)
        instance.constraint_columns = ('a', 'b')

        # Run
        instance.fit(table_data)

        # Assert
        gm_mock.assert_called_once_with(distribution=GaussianUnivariate)
示例#4
0
文件: test_base.py 项目: csala/SDV
    def test_fit(self):
        """Test the ``Constraint.fit`` method.

        The base ``Constraint.fit`` method is expected to:
        - Call ``_fit`` method.

        Input:
        - Table data (pandas.DataFrame)
        """
        # Setup
        table_data = pd.DataFrame({'a': [1, 2, 3]})
        instance = Constraint(handling_strategy='transform',
                              fit_columns_model=False)
        instance._fit = Mock()

        # Run
        instance.fit(table_data)

        # Assert
        instance._fit.assert_called_once_with(table_data)
示例#5
0
文件: test_base.py 项目: sdv-dev/SDV
    def test_fit(self):
        """Test the ``Constraint.fit`` method.

        The base ``Constraint.fit`` method is expected to:
        - Call ``_fit`` method.

        Input:
        - Table data (pandas.DataFrame)
        """
        # Setup
        table_data = pd.DataFrame({'a': [1, 2, 3]})
        instance = Constraint()
        instance._fit = Mock()
        instance._validate_data_meets_constraint = Mock()

        # Run
        instance.fit(table_data)

        # Assert
        instance._fit.assert_called_once_with(table_data)
        instance._validate_data_meets_constraint.assert_called_once_with(
            table_data)