Skip to content

Commit

Permalink
Add silent option to check_if_values_in_interval
Browse files Browse the repository at this point in the history
  • Loading branch information
bpalmeiro committed Dec 27, 2024
1 parent 1587472 commit 1b20e94
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions invisible_cities/core/core_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This module includes utility functions.
"""
import time
import warnings

import numpy as np

Expand Down Expand Up @@ -108,13 +109,24 @@ def check_if_values_in_interval(data : np.array,
True if values are in the interval. False if not and strictness
is set to 'warning'. Otherwise, it raises an exception.
"""
if in_range(data, minval, maxval, **kwargs).all():
return True;

values_in_interval = in_range(data, minval, maxval, **kwargs)
outsiders_mask = np.logical_not(values_in_interval)
outsiders_list = data[outsiders_mask]
n_outsiders = np.sum(outsiders_mask)

if values_in_interval.all():
return True

elif strictness is Strictness.warning:
warnings.warn(f' Variable {display_name} has {n_outsiders} values out of bounds ({minval}, {maxval})\n outsiders: {outsiders_list}')
return False

elif strictness is Strictness.silent:
return False

else:
raise ValueOutOfRange(f' Variable {display_name} is out of bounds ({minval}, {maxval})')
raise ValueOutOfRange(f' Variable {display_name} has {n_outsiders} values out of bounds ({minval}, {maxval})\n outsiders: {outsiders_list}')

return

Expand Down

0 comments on commit 1b20e94

Please sign in to comment.