Skip to content

Commit

Permalink
Add kscomplement fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fealho committed Nov 19, 2024
1 parent 5193369 commit 97538ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 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 @@ -57,6 +59,13 @@ def compute(real_data, synthetic_data):
real_data = pd.to_numeric(real_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)
except TypeError:
pass

try:
statistic, _ = ks_2samp(real_data, synthetic_data)
except ValueError as e:
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

0 comments on commit 97538ad

Please sign in to comment.