diff --git a/rdt/transformers/numerical.py b/rdt/transformers/numerical.py index 67e9c7379..f85e21a05 100644 --- a/rdt/transformers/numerical.py +++ b/rdt/transformers/numerical.py @@ -1,5 +1,6 @@ """Transformers for numerical data.""" import copy +import logging import sys import warnings @@ -11,6 +12,8 @@ from rdt.transformers.base import BaseTransformer from rdt.transformers.null import NullTransformer +LOGGER = logging.getLogger(__name__) + EPSILON = np.finfo(np.float32).eps MAX_DECIMALS = sys.float_info.dig - 1 INTEGER_BOUNDS = { @@ -109,8 +112,7 @@ def _learn_rounding_digits(data): return decimal # Can't round, not equal after MAX_DECIMALS digits of precision - warnings.warn( - f"No rounding scheme detected for column '{name}'. Data will not be rounded.") + LOGGER.info("No rounding scheme detected for column '%s'. Data will not be rounded.", name) return None def _raise_out_of_bounds_error(self, value, name, bound_type, min_bound, max_bound): diff --git a/tests/unit/transformers/test_numerical.py b/tests/unit/transformers/test_numerical.py index e007b35fe..36d26aad8 100644 --- a/tests/unit/transformers/test_numerical.py +++ b/tests/unit/transformers/test_numerical.py @@ -24,7 +24,8 @@ def test___init__super_attrs(self): assert nt.missing_value_replacement == 'mode' assert nt.missing_value_generation == 'random' - def test__learn_rounding_digits_more_than_15_decimals(self): + @patch('rdt.transformers.numerical.LOGGER') + def test__learn_rounding_digits_more_than_15_decimals(self, logger_mock): """Test the _learn_rounding_digits method with more than 15 decimals. If the data has more than 15 decimals, return None and raise warning. @@ -32,11 +33,12 @@ def test__learn_rounding_digits_more_than_15_decimals(self): # Setup data = pd.Series(np.random.random(size=10).round(20), name='col') - # Run and Assert - warn_msg = "No rounding scheme detected for column 'col'. Data will not be rounded." - with pytest.warns(UserWarning, match=warn_msg): - output = FloatFormatter._learn_rounding_digits(data) + # Run + output = FloatFormatter._learn_rounding_digits(data) + # Assert + logger_msg = "No rounding scheme detected for column '%s'. Data will not be rounded." + logger_mock.info.assert_called_once_with(logger_msg, 'col') assert output is None def test__learn_rounding_digits_less_than_15_decimals(self):