Ejemplo n.º 1
0
    def test_reverse_transform(self):
        """Test the ``GreaterThan.reverse_transform`` method.

        The ``GreaterThan.reverse_transform`` method is expected to:
        - Return the original table data.

        Input:
        - Table data transformed (pandas.DataFrame)
        Output:
        - Table data (pandas.DataFrame)
        Side effects:
        - Since ``reverse_transform`` uses the class variable ``_dtype``, the ``fit`` method
        must be called as well.
        """
        # Setup
        table_data = pd.DataFrame({
            'a': [1, 2, 3],
            'b': [4, 5, 6],
            'c': [7, 8, 9]
        })
        instance = GreaterThan(low='a', high='b', strict=True)
        instance.fit(table_data)

        # Run
        out = instance.reverse_transform(table_data)

        # Assert
        expected_out = pd.DataFrame({
            'a': [1, 2, 3],
            'b': [55, 149, 405],
            'c': [7, 8, 9],
        })
        pd.testing.assert_frame_equal(out, expected_out)
Ejemplo n.º 2
0
    def test_fit_float(self):
        """Test the ``GreaterThan.fit`` method.

        The ``GreaterThan.fit`` method should only learn and store the
        ``dtype`` of the ``high`` column as the ``_dtype`` attribute.

        Input:
        - Table that contains two constrained columns with the high one
          being made of float values.
        Side Effect:
        - The _dtype attribute gets `float` as the value even if the low
          column has a different dtype.
        """
        # Setup
        instance = GreaterThan(low='a', high='b')

        # Run
        table_data = pd.DataFrame({
            'a': [1, 2, 3],
            'b': [4., 5., 6.],
            'c': [7, 8, 9]
        })
        instance.fit(table_data)

        # Asserts
        assert instance._dtype.kind == 'f'
Ejemplo n.º 3
0
    def test_fit_datetime(self):
        """Test the ``GreaterThan.fit`` method.

        The ``GreaterThan.fit`` method should only learn and store the
        ``dtype`` of the ``high`` column as the ``_dtype`` attribute.

        Input:
        - Table that contains two constrained columns of datetimes.
        Side Effect:
        - The _dtype attribute gets `datetime` as the value.
        """
        # Setup
        instance = GreaterThan(low='a', high='b')

        # Run
        table_data = pd.DataFrame({
            'a': pd.to_datetime(['2020-01-01']),
            'b': pd.to_datetime(['2020-01-02'])
        })
        instance.fit(table_data)

        # Asserts
        assert instance._dtype.kind == 'M'
Ejemplo n.º 4
0
    def test_fit(self):
        """Test the ``GreaterThan.fit`` method.

        It is expected to return the dtype of the ``high`` column.

        Input:
        - Table data (pandas.DataFrame)
        Output:
        - dtype of the ``high`` column.
        """
        # Setup
        instance = GreaterThan(low='a', high='b')

        # Run
        table_data = pd.DataFrame({
            'a': [1, 2, 3],
            'b': [4, 5, 6],
            'c': [7, 8, 9]
        })
        instance.fit(table_data)

        # Asserts
        expected = table_data['b'].dtype
        assert instance._dtype == expected