From e9bb577e98b6a0b39cdc1ce9803eb82c3031bffb Mon Sep 17 00:00:00 2001 From: R-Palazzo <116157184+R-Palazzo@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:45:17 -0600 Subject: [PATCH] Single table Structure property should not have visualization (#512) --- sdmetrics/errors.py | 4 +++ .../single_table/_properties/structure.py | 29 ++++--------------- .../_properties/test_structure.py | 15 ++++++++++ 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/sdmetrics/errors.py b/sdmetrics/errors.py index 4d8560aa..8fb0e211 100644 --- a/sdmetrics/errors.py +++ b/sdmetrics/errors.py @@ -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.""" diff --git a/sdmetrics/reports/single_table/_properties/structure.py b/sdmetrics/reports/single_table/_properties/structure.py index 56b25949..7d539863 100644 --- a/sdmetrics/reports/single_table/_properties/structure.py +++ b/sdmetrics/reports/single_table/_properties/structure.py @@ -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 @@ -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 diff --git a/tests/unit/reports/single_table/_properties/test_structure.py b/tests/unit/reports/single_table/_properties/test_structure.py index 1ef1e744..154a35a6 100644 --- a/tests/unit/reports/single_table/_properties/test_structure.py +++ b/tests/unit/reports/single_table/_properties/test_structure.py @@ -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 @@ -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()