Skip to content

Commit

Permalink
Fix floating point
Browse files Browse the repository at this point in the history
  • Loading branch information
fealho committed Nov 15, 2024
1 parent 5c0273b commit d6654d7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdmetrics/single_column/statistical/kscomplement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Kolmogorov-Smirnov test based Metric."""

import sys

import numpy as np
import pandas as pd
from scipy.stats import ks_2samp
Expand Down Expand Up @@ -58,6 +60,9 @@ def compute(real_data, synthetic_data):
synthetic_data = pd.to_numeric(synthetic_data)

try:
max_decimals = sys.float_info.dig - 1
real_data = real_data.round(max_decimals)
synthetic_data = synthetic_data.round(max_decimals)
statistic, _ = ks_2samp(real_data, synthetic_data)
except ValueError as e:
if str(e) == 'Data passed to ks_2samp must not be empty':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@ def test_bad(array_like):

assert 0.0 <= output < 0.5
assert 0.0 <= normalized < 0.5


def test_one_float_value():
real = pd.Series([0.3 - 0.2])
synth = pd.Series([0.2 - 0.1])
output = KSComplement.compute(real, synth)
assert output == 1
18 changes: 18 additions & 0 deletions tests/unit/timeseries/test_inter_row_msas.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ def test_compute_with_log(self):
# Assert
assert score == 1

def test_compute_with_log_distinct_data(self):
"""Test it with logarithmic transformation distinct data."""
# Setup
real_keys = pd.Series(['id1', 'id1', 'id1', 'id2', 'id2', 'id2'])
real_values = pd.Series([1, 2, 4, 12, 24, 48])
synthetic_keys = pd.Series(['id1', 'id1', 'id1', 'id2', 'id2', 'id2'])
synthetic_values = pd.Series([3, 6, 12, 5, 10, 20])

# Run
score = InterRowMSAS.compute(
real_data=(real_keys, real_values),
synthetic_data=(synthetic_keys, synthetic_values),
apply_log=True,
)

# Assert
assert score == 1

def test_compute_different_n_rows_diff(self):
"""Test it with different n_rows_diff."""
# Setup
Expand Down

0 comments on commit d6654d7

Please sign in to comment.