def test_reverse_transform_rounding_negative_rounding_int(self): """Test ``reverse_transform`` when ``rounding`` is a negative int The data should round to the number set in the ``_rounding_digits`` attribute and remain ints. Input: - Array with with floats above 100 Output: - Same array rounded to the provided number of 0s - Array should be of type int """ # Setup data = np.array([2000.0, 120.0, 3100.0, 40100.0]) # Run transformer = NumericalTransformer(dtype=np.int, nan=None) transformer._dtype = np.int transformer._rounding_digits = -3 result = transformer.reverse_transform(data) # Assert expected_data = np.array([2000, 0, 3000, 40000]) np.testing.assert_array_equal(result, expected_data) assert result.dtype == np.int
def test_reverse_transform_rounding_none_with_nulls(self): """Test ``reverse_transform`` when ``rounding`` is ``None`` and there are nulls. The data should not be rounded at all. Input: - 2d Array of multiple float values with decimals and a column setting at least 1 null. Output: - First column of the input array as entered, replacing the indicated value with a Nan. """ # Setup data = np.array([ [0., 0.], [1.2, 0.], [3.45, 1.], [6.789, 0.], ]) # Run transformer = NumericalTransformer() null_transformer = Mock() null_transformer.reverse_transform.return_value = np.array( [0., 1.2, np.nan, 6.789]) transformer.null_transformer = null_transformer transformer._rounding_digits = None transformer._dtype = np.float result = transformer.reverse_transform(data) # Assert expected = np.array([0., 1.2, np.nan, 6.789]) np.testing.assert_array_equal(result, expected)
def test_reverse_transform_rounding_none_with_nulls_dtype_int(self): """Test ``reverse_transform`` when rounding is None, dtype is int and there are nulls. The data should be rounded to 0 decimals and returned as float values with nulls in the right place. Input: - 2d Array of multiple float values with decimals and a column setting at least 1 null. Output: - First column of the input array rounded, replacing the indicated value with a Nan, and kept as float values. """ # Setup data = np.array([ [0., 0.], [1.2, 0.], [3.45, 1.], [6.789, 0.], ]) # Run transformer = NumericalTransformer() null_transformer = Mock() null_transformer.reverse_transform.return_value = np.array( [0., 1.2, np.nan, 6.789]) transformer.null_transformer = null_transformer transformer._rounding_digits = None transformer._dtype = np.int result = transformer.reverse_transform(data) # Assert expected = np.array([0., 1., np.nan, 7.]) np.testing.assert_array_equal(result, expected)
def test_reverse_transform_rounding_none_integer(self): """Test ``reverse_transform`` when ``rounding`` is ``None`` and the dtype is integer. The data should be rounded to 0 decimals and returned as integer values. Input: - Array of multiple float values with decimals. Output: - Input array rounded an converted to integers. """ # Setup data = np.array([0., 1.2, 3.45, 6.789]) # Run transformer = NumericalTransformer(dtype=np.int64, nan=None) transformer._rounding_digits = None transformer._dtype = np.int64 result = transformer.reverse_transform(data) # Assert expected = np.array([0, 1, 3, 7]) np.testing.assert_array_equal(result, expected)