def test_transform_datetime(self): """Test the ``GreaterThan.transform`` method passing a high column of type datetime. If the columns are of type datetime, ``transform`` is expected to convert the timedelta distance into numeric before applying the +1 and logarithm. Input: - Table with values at a distance of exactly 1 second. Output: - Same table with the high column transformed into the logarithms of the dinstance in nanoseconds + 1, which is np.log(1_000_000_001). """ # Setup instance = GreaterThan(low='a', high='b', strict=True) # Run table_data = pd.DataFrame({ 'a': pd.to_datetime(['2020-01-01T00:00:00', '2020-01-02T00:00:00']), 'b': pd.to_datetime(['2020-01-01T00:00:01', '2020-01-02T00:00:01']), 'c': [1, 2], }) out = instance.transform(table_data) # Assert expected_out = 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], })
def test_transform_float(self): """Test the ``GreaterThan.transform`` method passing a high column of type float. The ``GreaterThan.transform`` method is expected to compute the distance between the high and low columns and replace the high column with the logarithm of the distance + 1. Input: - Table with two constrained columns at a constant distance of exactly 3 and one additional dummy column. Output: - Same table with the high column transformed into the logarithms of the distances + 1, which is np.log(4). """ # Setup instance = GreaterThan(low='a', high='b', strict=True) # Run table_data = pd.DataFrame({ 'a': [1, 2, 3], 'b': [4., 5., 6.], 'c': [7, 8, 9], }) out = instance.transform(table_data) # Assert expected_out = pd.DataFrame({ 'a': [1, 2, 3], 'b': [np.log(4)] * 3, 'c': [7, 8, 9], }) pd.testing.assert_frame_equal(out, expected_out)
def test_transform(self): """Test the ``GreaterThan.transform`` method. The ``GreaterThan.transform`` method is expected to: - Transform the original table data. Input: - Table data (pandas.DataFrame) Output: - Table data transformed (pandas.DataFrame) """ # Setup instance = GreaterThan(low='a', high='b', strict=True) # Run table_data = pd.DataFrame({ 'a': [1, 2, 3], 'b': [4, 5, 6], }) out = instance.transform(table_data) # Assert expected_out = pd.DataFrame({ 'a': [1, 2, 3], 'b': [1.3862944, 1.3862944, 1.3862944] }) pd.testing.assert_frame_equal(out, expected_out)
def test_transform_not_all_columns_provided(self): """Test the ``GreaterThan.transform`` method. If some of the columns needed for the transform are missing, it will raise a ``MissingConstraintColumnError``. Input: - Table data (pandas.DataFrame) Output: - Raises ``MissingConstraintColumnError``. """ # Setup instance = GreaterThan(low='a', high='b', strict=True) # Run/Assert with pytest.raises(MissingConstraintColumnError): instance.transform(pd.DataFrame({'a': ['a', 'b', 'c']}))