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

Single table Structure property should not have visualization #512

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
4 changes: 4 additions & 0 deletions sdmetrics/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Custom errors for SDMetrics."""


class VisualizationUnavailableError(Exception):
"""Raised when a visualization is not available."""


class IncomputableMetricError(Exception):
"""Raised when a metric cannot be computed."""

Expand Down
29 changes: 6 additions & 23 deletions sdmetrics/reports/single_table/_properties/structure.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pandas as pd
import plotly.express as px

from sdmetrics.errors import VisualizationUnavailableError
from sdmetrics.reports.single_table._properties import BaseSingleTableProperty
from sdmetrics.single_table import TableFormat

Expand Down Expand Up @@ -69,28 +69,11 @@ def _generate_details(self, real_data, synthetic_data, metadata, progress_bar=No
return result

def get_visualization(self):
"""Create a plot to show the structure property score.
"""Return the visualization for the property.

Returns:
plotly.graph_objects._figure.Figure
Raise an error in this case because the single table Structure property
does not have a supported visualization.
"""
average_score = self._compute_average()

fig = px.bar(
data_frame=self.details.dropna(subset=['Score']),
y='Score',
title=f'Data Diagnostic: Structure (Average Score={round(average_score, 2)})',
color='Metric',
pattern_shape='Metric',
raise VisualizationUnavailableError(
'The single table Structure property does not have a supported visualization.'
)

fig.update_yaxes(range=[0, 1], title_text='Diagnostic Score')

fig.update_layout(
xaxis_categoryorder='total ascending',
plot_bgcolor='#F5F5F8',
margin={'t': 150},
xaxis_title='Table',
)

return fig
15 changes: 15 additions & 0 deletions tests/unit/reports/single_table/_properties/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import numpy as np
import pandas as pd
import pytest

from sdmetrics.errors import VisualizationUnavailableError
from sdmetrics.reports.single_table._properties.structure import Structure


Expand Down Expand Up @@ -84,3 +86,16 @@ def test__generate_details_with_id_column(self, table_format_mock):
'Score': 0.75,
}, index=[0])
pd.testing.assert_frame_equal(result, expected_details)

def test_get_visualization(self):
"""Test the ``get_visualization`` method."""
# Setup
structure_property = Structure()

# Run and Assert
expected_message = (
'The single table Structure property does not have a'
' supported visualization.'
)
with pytest.raises(VisualizationUnavailableError, match=expected_message):
structure_property.get_visualization()
Loading