Skip to content

Commit

Permalink
When no rounding scheme is detected, log the info instead of showing …
Browse files Browse the repository at this point in the history
…a warning (#712)
  • Loading branch information
frances-h authored Sep 19, 2023
1 parent 46d523a commit 48fc92b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions rdt/transformers/numerical.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Transformers for numerical data."""
import copy
import logging
import sys
import warnings

Expand All @@ -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 = {
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/transformers/test_numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ 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.
"""
# 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):
Expand Down

0 comments on commit 48fc92b

Please sign in to comment.