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)
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)
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)