Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make evaluate methods return the actual object #1253

Merged
merged 3 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions sdv/evaluation/multi_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def evaluate_quality(real_data, synthetic_data, metadata, verbose=True):
Defaults to True.

Returns:
float:
The overall quality score.
QualityReport:
Multi table quality report object.
"""
quality_report = QualityReport()
quality_report.generate(real_data, synthetic_data, metadata.to_dict(), verbose)
return quality_report.get_score()
return quality_report


def run_diagnostic(real_data, synthetic_data, metadata, verbose=True):
Expand All @@ -42,12 +42,12 @@ def run_diagnostic(real_data, synthetic_data, metadata, verbose=True):
Defaults to True.

Returns:
dict:
The diagonstic results.
DiagnosticReport:
Multi table diagnostic report object.
"""
quality_report = DiagnosticReport()
quality_report.generate(real_data, synthetic_data, metadata.to_dict(), verbose)
return quality_report.get_results()
diagnostic_report = DiagnosticReport()
diagnostic_report.generate(real_data, synthetic_data, metadata.to_dict(), verbose)
return diagnostic_report


def get_column_plot(real_data, synthetic_data, metadata, table_name, column_name):
Expand Down
16 changes: 8 additions & 8 deletions sdv/evaluation/single_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def evaluate_quality(real_data, synthetic_data, metadata, verbose=True):
Defaults to True.

Returns:
float
The overall quality score.
QualityReport:
Single table quality report object.
"""
quality_report = QualityReport()
quality_report.generate(real_data, synthetic_data, metadata.to_dict(), verbose)
return quality_report.get_score()
return quality_report


def run_diagnostic(real_data, synthetic_data, metadata, verbose=True):
Expand All @@ -43,12 +43,12 @@ def run_diagnostic(real_data, synthetic_data, metadata, verbose=True):
Defaults to True.

Returns:
dict:
The diagonstic results.
DiagnosticReport:
Single table diagnostic report object.
"""
quality_report = DiagnosticReport()
quality_report.generate(real_data, synthetic_data, metadata.to_dict(), verbose)
return quality_report.get_results()
diagnostic_report = DiagnosticReport()
diagnostic_report.generate(real_data, synthetic_data, metadata.to_dict(), verbose)
return diagnostic_report


def get_column_plot(real_data, synthetic_data, metadata, column_name):
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/evaluation/test_multi_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def test_evaluation():
# Run and Assert
synthesizer.fit(data)
samples = synthesizer.sample()
score = evaluate_quality(data, samples, metadata)
score = evaluate_quality(data, samples, metadata).get_score()
assert score == 0.6666666666666667

diagnostic = run_diagnostic(data, samples, metadata)
diagnostic = run_diagnostic(data, samples, metadata).get_results()
assert diagnostic == {
'DANGER': ['More than 50% of the synthetic rows are copies of the real data'],
'SUCCESS': [
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/evaluation/test_single_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def test_evaluation():
# Run and Assert
synthesizer.fit(data)
samples = synthesizer.sample(10)
score = evaluate_quality(data, samples, metadata)
score = evaluate_quality(data, samples, metadata).get_score()
assert score == 0.8333333333333334

diagnostic = run_diagnostic(data, samples, metadata)
diagnostic = run_diagnostic(data, samples, metadata).get_results()
assert diagnostic == {
'DANGER': ['More than 50% of the synthetic rows are copies of the real data'],
'SUCCESS': [
Expand Down
14 changes: 4 additions & 10 deletions tests/unit/evaluation/test_multi_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,37 @@


def test_evaluate_quality():
"""Test the correct score is returned."""
"""Test ``generate`` is called for the ``QualityReport`` object."""
# Setup
table = pd.DataFrame({'col': [1, 2, 3]})
data1 = {'table': table}
data2 = {'table': pd.DataFrame({'col': [2, 1, 3]})}
metadata = MultiTableMetadata()
metadata.detect_table_from_dataframe('table', table)
QualityReport.generate = Mock()
QualityReport.get_score = Mock(return_value=123)

# Run
score = evaluate_quality(data1, data2, metadata)
evaluate_quality(data1, data2, metadata)

# Assert
QualityReport.generate.assert_called_once_with(data1, data2, metadata.to_dict(), True)
QualityReport.get_score.assert_called_once_with()
assert score == 123


def test_run_diagnostic():
"""Test the correct diagnostic is returned."""
"""Test ``generate`` is called for the ``DiagnosticReport`` object."""
# Setup
table = pd.DataFrame({'col': [1, 2, 3]})
data1 = {'table': table}
data2 = {'table': pd.DataFrame({'col': [2, 1, 3]})}
metadata = MultiTableMetadata()
metadata.detect_table_from_dataframe('table', table)
DiagnosticReport.generate = Mock()
DiagnosticReport.get_results = Mock(return_value={'err_type': 'str'})

# Run
diagnostic = run_diagnostic(data1, data2, metadata)
run_diagnostic(data1, data2, metadata)

# Assert
DiagnosticReport.generate.assert_called_once_with(data1, data2, metadata.to_dict(), True)
DiagnosticReport.get_results.assert_called_once_with()
assert diagnostic == {'err_type': 'str'}


@patch('sdmetrics.reports.utils.get_column_plot')
Expand Down
17 changes: 5 additions & 12 deletions tests/unit/evaluation/test_single_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,35 @@


def test_evaluate_quality():
"""Test the correct score is returned."""
"""Test ``generate`` is called for the ``QualityReport`` object."""
# Setup
data1 = pd.DataFrame({'col': [1, 2, 3]})
data2 = pd.DataFrame({'col': [2, 1, 3]})
metadata = SingleTableMetadata()
metadata.add_column('col', sdtype='numerical')
QualityReport.generate = Mock()
QualityReport.get_score = Mock(return_value=123)

# Run
score = evaluate_quality(data1, data2, metadata)
evaluate_quality(data1, data2, metadata)

# Assert
QualityReport.generate.assert_called_once_with(data1, data2, metadata.to_dict(), True)
QualityReport.get_score.assert_called_once_with()
assert score == 123


def test_run_diagnostic():
"""Test the correct diagnostic is returned."""
"""Test ``generate`` is called for the ``DiagnosticReport`` object."""
# Setup
data1 = pd.DataFrame({'col': [1, 2, 3]})
data2 = pd.DataFrame({'col': [2, 1, 3]})
metadata = SingleTableMetadata()
metadata.add_column('col', sdtype='numerical')
DiagnosticReport.generate = Mock()
DiagnosticReport.get_results = Mock(return_value={'err_type': 'str'})
DiagnosticReport.generate = Mock(return_value=123)

# Run
diagnostic = run_diagnostic(data1, data2, metadata)
run_diagnostic(data1, data2, metadata)

# Assert
DiagnosticReport.generate.assert_called_once_with(data1, data2, metadata.to_dict(), True)
DiagnosticReport.get_results.assert_called_once_with()
assert diagnostic == {'err_type': 'str'}


@patch('sdmetrics.reports.utils.get_column_plot')
Expand All @@ -58,7 +52,6 @@ def test_get_column_plot(mock_plot):
mock_plot.return_value = 'plot'

# Run
# method produces non uniform for [1,2,3] data, maybe bugged?
plot = get_column_plot(data1, data2, metadata, 'col')

# Assert
Expand Down