Skip to content

Commit c002c45

Browse files
author
Sushanth Sathish Kumar
committed
chore: fix style issues
1 parent 3292e1c commit c002c45

File tree

7 files changed

+134
-55
lines changed

7 files changed

+134
-55
lines changed

src/sagemaker/dashboard/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from sagemaker.dashboard.data_quality_dashboard import AutomaticDataQualityDashboard # noqa: F401
2222
from sagemaker.dashboard.model_quality_dashboard import AutomaticModelQualityDashboard # noqa: F401
2323
from sagemaker.dashboard.dashboard_variables import DashboardVariable # noqa: F401
24-
from sagemaker.dashboard.dashboard_widgets import (
25-
DashboardWidget, # noqa: F401
26-
DashboardWidgetProperties, # noqa: F401
27-
)
24+
from sagemaker.dashboard.dashboard_widgets import ( # noqa: F401
25+
DashboardWidget,
26+
DashboardWidgetProperties,
27+
)

src/sagemaker/dashboard/dashboard_variables.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
These classes assist with creating dashboards in Python3 and then using boto3 CloudWatch client
1616
to publish the generated dashboards. To be used to aid dashboard creation in ClarifyModelMonitor
17-
and ModelMonitor.
17+
and ModelMonitor.
1818
"""
1919
from __future__ import absolute_import
2020
import json
@@ -44,7 +44,7 @@ def __init__(
4444
inputType (str): Type of input field ('input', 'select', or 'radio') for user interaction.
4545
variable_id (str): Identifier for the variable, up to 32 characters.
4646
label (str, optional): Label displayed for the input field (default is None).
47-
search (str, optional): Metric search expression to populate input options (required for 'select' or 'radio').
47+
search (str, optional): Metric search expression to populate input options.
4848
populateFrom (str, optional): Dimension name used to populate input options from search results.
4949
"""
5050
self.variable_type = variable_type

src/sagemaker/dashboard/dashboard_widgets.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
1515
These classes assist with creating dashboards in Python3 and then using boto3 CloudWatch client
1616
to publish the generated dashboards. To be used to aid dashboard creation in ClarifyModelMonitor
17-
and ModelMonitor.
17+
and ModelMonitor.
1818
"""
1919
from __future__ import absolute_import
2020
import json
2121

2222

2323
class DashboardWidgetProperties:
24-
"""
25-
Represents properties of a dashboard widget used for metrics in CloudWatch.
24+
"""Represents properties of a dashboard widget used for metrics in CloudWatch.
2625
2726
Attributes:
2827
view (str): Type of visualization ('timeSeries', 'singleValue', 'gauge', 'bar', 'pie', 'table').
@@ -44,8 +43,7 @@ def __init__(
4443
title=None,
4544
markdown=None,
4645
):
47-
"""
48-
Initializes DashboardWidgetProperties instance.
46+
"""Initializes DashboardWidgetProperties instance.
4947
5048
Args:
5149
view (str, optional): Type of visualization ('timeSeries', 'singleValue', 'gauge', 'bar', 'pie', 'table').
@@ -65,8 +63,7 @@ def __init__(
6563
self.markdown = markdown
6664

6765
def to_dict(self):
68-
"""
69-
Converts DashboardWidgetProperties instance to a dictionary representation.
66+
"""Converts DashboardWidgetProperties instance to a dictionary representation.
7067
7168
Returns:
7269
dict: Dictionary containing widget properties suitable for JSON serialization.
@@ -89,8 +86,7 @@ def to_dict(self):
8986
return widget_properties_dict
9087

9188
def to_json(self):
92-
"""
93-
Converts DashboardWidgetProperties instance to a JSON string.
89+
"""Converts DashboardWidgetProperties instance to a JSON string.
9490
9591
Returns:
9692
str: JSON string representation of the widget properties.
@@ -99,8 +95,7 @@ def to_json(self):
9995

10096

10197
class DashboardWidget:
102-
"""
103-
Represents a widget in a CloudWatch dashboard.
98+
"""Represents a widget in a CloudWatch dashboard.
10499
105100
Attributes:
106101
height (int): Height of the widget.
@@ -110,8 +105,7 @@ class DashboardWidget:
110105
"""
111106

112107
def __init__(self, height, width, widget_type, properties=None):
113-
"""
114-
Initializes DashboardWidget instance.
108+
"""Initializes DashboardWidget instance.
115109
116110
Args:
117111
height (int): Height of the widget.
@@ -129,8 +123,7 @@ def __init__(self, height, width, widget_type, properties=None):
129123
)
130124

131125
def to_dict(self):
132-
"""
133-
Converts DashboardWidget instance to a dictionary representation.
126+
"""Converts DashboardWidget instance to a dictionary representation.
134127
135128
Returns:
136129
dict: Dictionary containing widget attributes suitable for JSON serialization.
@@ -143,8 +136,7 @@ def to_dict(self):
143136
}
144137

145138
def to_json(self):
146-
"""
147-
Converts DashboardWidget instance to a JSON string.
139+
"""Converts DashboardWidget instance to a JSON string.
148140
149141
Returns:
150142
str: JSON string representation of the widget attributes.

src/sagemaker/dashboard/data_quality_dashboard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
"""This module the wrapper class for data quality dashboard.
13+
"""This module the wrapper class for data quality dashboard.
1414
15-
To be used to aid dashboard creation in ModelMonitor.
15+
To be used to aid dashboard creation in ModelMonitor.
1616
"""
1717
from __future__ import absolute_import
1818

src/sagemaker/dashboard/model_quality_dashboard.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You
4+
# may not use this file except in compliance with the License. A copy of
5+
# the License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is
10+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11+
# ANY KIND, either express or implied. See the License for the specific
12+
# language governing permissions and limitations under the License.
13+
"""This module the wrapper class for model quality dashboard.
14+
15+
To be used to aid dashboard creation in ModelMonitor.
16+
"""
17+
118
from __future__ import absolute_import
219
import json
320
from sagemaker.dashboard.dashboard_widgets import DashboardWidget, DashboardWidgetProperties
@@ -6,13 +23,6 @@
623
class AutomaticModelQualityDashboard:
724
"""Represents a dashboard for automatic model quality metrics in Amazon SageMaker.
825
9-
Attributes:
10-
MODEL_QUALITY_METRICS_ENDPOINT_NAMESPACE (str): Namespace for model metrics at endpoint level.
11-
MODEL_QUALITY_METRICS_BATCH_NAMESPACE (str): Namespace for model metrics at batch transform level.
12-
REGRESSION_MODEL_QUALITY_METRICS (list): List of regression model quality metrics and their graphs.
13-
BINARY_CLASSIFICATION_MODEL_QUALITY_METRICS (list): List of binary classification model quality metrics and their graphs.
14-
MULTICLASS_CLASSIFICATION_MODEL_QUALITY_METRICS (list): List of multiclass classification model quality metrics and their graphs.
15-
1626
Methods:
1727
__init__(self, endpoint_name, monitoring_schedule_name, batch_transform_input, problem_type, region_name):
1828
Initializes an AutomaticModelQualityDashboard instance.
@@ -134,7 +144,8 @@ def _generate_widgets(self):
134144
)
135145
else:
136146
raise ValueError(
137-
"Parameter problem_type is invalid. Valid options are Regression, BinaryClassification, or MulticlassClassification."
147+
"Parameter problem_type is invalid. Valid options are "
148+
"Regression, BinaryClassification, or MulticlassClassification."
138149
)
139150

140151
for graphs_per_line in metrics_to_graph:
@@ -150,10 +161,10 @@ def _generate_widgets(self):
150161
[
151162
{
152163
"expression": (
153-
f"SEARCH( '{AutomaticModelQualityDashboard.MODEL_QUALITY_METRICS_BATCH_NAMESPACE} "
164+
f"SEARCH( '{self.MODEL_QUALITY_METRICS_BATCH_NAMESPACE} "
154165
f"{metrics_string} "
155166
f'MonitoringSchedule="{self.monitoring_schedule}" \', '
156-
f"'Average')"
167+
"'Average')"
157168
)
158169
}
159170
]
@@ -169,7 +180,7 @@ def _generate_widgets(self):
169180
[
170181
{
171182
"expression": (
172-
f"SEARCH( '{AutomaticModelQualityDashboard.MODEL_QUALITY_METRICS_ENDPOINT_NAMESPACE} "
183+
f"SEARCH( '{self.MODEL_QUALITY_METRICS_ENDPOINT_NAMESPACE} "
173184
f"{metrics_string} "
174185
f'Endpoint="{self.endpoint}" '
175186
f'MonitoringSchedule="{self.monitoring_schedule}" \', '

src/sagemaker/model_monitor/model_monitoring.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,8 +1546,7 @@ def _check_dashboard_validity_without_checking_in_use(
15461546
enable_automatic_dashboard=False,
15471547
dashboard_name=None,
15481548
):
1549-
"""Checks if the parameters provided to generate an automatic dashboard are valid,
1550-
but does not check if the dashboard is already in use.
1549+
"""Checks if the parameters are valid, without checking if dashboard name is taken
15511550
15521551
Args:
15531552
monitor_schedule_name (str): Monitoring schedule name.
@@ -1610,11 +1609,11 @@ def _check_automatic_dashboard_validity(
16101609
enable_automatic_dashboard=enable_automatic_dashboard,
16111610
dashboard_name=dashboard_name,
16121611
)
1612+
cw_client = self.sagemaker_session.boto_session.client("cloudwatch")
16131613

16141614
if enable_automatic_dashboard:
16151615
try:
16161616
# try to access the dashboard to see if it exists already
1617-
cw_client = self.sagemaker_session.boto_session.client("cloudwatch")
16181617
cw_client.get_dashboard(DashboardName=dashboard_name)
16191618
message = (
16201619
f"Dashboard name {dashboard_name} is already in use. "
@@ -1623,11 +1622,11 @@ def _check_automatic_dashboard_validity(
16231622
)
16241623
_LOGGER.error(message)
16251624
raise ValueError(message)
1626-
except Exception as _:
1625+
except Exception as e:
1626+
_LOGGER.log(f"Correctly received error {e}.")
16271627
# in this case, the dashboard name is not in use
16281628
# and we are free to write to it without overwriting any
16291629
# customer data.
1630-
pass
16311630

16321631
def _create_monitoring_schedule_from_job_definition(
16331632
self,

0 commit comments

Comments
 (0)