@@ -52,8 +52,14 @@ def normalize_by_sd(self, dist, var: ContinuousVariable) -> ContinuousVariable:
5252 compute_val = Norm (var , avg , 1 / sd )
5353 else :
5454 compute_val = Norm (var , 0 , 1 / sd )
55- num_decimals = var .number_of_decimals + int (np .ceil (np .log10 (sd )))
56- num_decimals = max (num_decimals , 0 ) # num decimals can't be negative
55+
56+ # When dealing with integers, and multiplying by something smaller than
57+ # 1, the number of decimals should be decreased, but this integer will
58+ # likely turn into a float, which should have some default number of
59+ # decimals
60+ num_decimals = var .number_of_decimals + int (np .round (np .log10 (sd )))
61+ num_decimals = max (num_decimals , 3 ) # num decimals can't be negative
62+
5763 return var .copy (compute_value = compute_val , number_of_decimals = num_decimals )
5864
5965 def normalize_by_span (self , dist , var : ContinuousVariable ) -> ContinuousVariable :
@@ -65,6 +71,9 @@ def normalize_by_span(self, dist, var: ContinuousVariable) -> ContinuousVariable
6571 compute_val = Norm (var , dmi , 1 / diff )
6672 else :
6773 compute_val = Norm (var , (dma + dmi ) / 2 , 2 / diff )
68- num_decimals = var .number_of_decimals + int (np .ceil (np .log10 (diff )))
69- num_decimals = max (num_decimals , 0 ) # num decimals can't be negative
70- return var .copy (compute_value = compute_val , number_of_decimals = num_decimals )
74+ if not np .isnan (diff ):
75+ num_decimals = var .number_of_decimals + int (np .ceil (np .log10 (diff )))
76+ num_decimals = max (num_decimals , 0 ) # num decimals can't be negative
77+ return var .copy (compute_value = compute_val , number_of_decimals = num_decimals )
78+ else :
79+ return var .copy (compute_value = compute_val )
0 commit comments