Example #1
0
    def test_reverse_transform_float(self):
        """Test the ``GreaterThan.reverse_transform`` method for dtype float.

        The ``GreaterThan.reverse_transform`` method is expected to:
            - apply an exponential to the input
            - subtract 1
            - add the low column
            - convert the output to float values

        Input:
        - Table with a high column that contains the constant np.log(4).
        Output:
        - Same table with the high column replaced by the low one + 3, as float values.
        """
        # Setup
        instance = GreaterThan(low='a', high='b', strict=True)
        instance._dtype = np.dtype('float')

        # Run
        transformed = pd.DataFrame({
            'a': [1.1, 2.2, 3.3],
            'b': [np.log(4)] * 3,
            'c': [7, 8, 9]
        })
        out = instance.reverse_transform(transformed)

        # Assert
        expected_out = pd.DataFrame({
            'a': [1.1, 2.2, 3.3],
            'b': [4.1, 5.2, 6.3],
            'c': [7, 8, 9],
        })
        pd.testing.assert_frame_equal(out, expected_out)
Example #2
0
    def test_reverse_transform_datetime(self):
        """Test the ``GreaterThan.reverse_transform`` method for dtype datetime.

        The ``GreaterThan.reverse_transform`` method is expected to:
            - apply an exponential to the input
            - subtract 1
            - convert the distance to a timedelta
            - add the low column
            - convert the output to datetimes

        Input:
        - Table with a high column that contains the constant np.log(1_000_000_001).
        Output:
        - Same table with the high column replaced by the low one + one second.
        """
        # Setup
        instance = GreaterThan(low='a', high='b', strict=True)
        instance._dtype = np.dtype('<M8[ns]')

        # Run
        transformed = pd.DataFrame({
            'a':
            pd.to_datetime(['2020-01-01T00:00:00', '2020-01-02T00:00:00']),
            'b': [np.log(1_000_000_001),
                  np.log(1_000_000_001)],
            'c': [1, 2]
        })
Example #3
0
    def test_reverse_transform_int(self):
        """Test the ``GreaterThan.reverse_transform`` method for dtype int.

        The ``GreaterThan.reverse_transform`` method is expected to:
            - apply an exponential to the input
            - subtract 1
            - add the low column
            - convert the output to integers

        Input:
        - Table with a high column that contains the constant np.log(4).
        Output:
        - Same table with the high column replaced by the low one + 3, as int.
        """
        # Setup
        instance = GreaterThan(low='a', high='b', strict=True)
        instance._dtype = pd.Series(
            [1]).dtype  # exact dtype (32 or 64) depends on OS

        # Run
        transformed = pd.DataFrame({
            'a': [1, 2, 3],
            'b': [np.log(4)] * 3,
            'c': [7, 8, 9]
        })
        out = instance.reverse_transform(transformed)

        # Assert
        expected_out = pd.DataFrame({
            'a': [1, 2, 3],
            'b': [4, 5, 6],
            'c': [7, 8, 9],
        })
        pd.testing.assert_frame_equal(out, expected_out)