Skip to content

Commit 6d11e3c

Browse files
[Bug fix] Report generator script for PII operator (#1149)
1 parent e65f09c commit 6d11e3c

File tree

2 files changed

+20
-36
lines changed

2 files changed

+20
-36
lines changed

ads/dataset/recommendation.py

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8; -*-
32

4-
# Copyright (c) 2020, 2022 Oracle and/or its affiliates.
3+
# Copyright (c) 2020, 2025 Oracle and/or its affiliates.
54
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
65

76
import copy
87
import importlib
98

109
from ads.common.decorator.runtime_dependency import (
11-
runtime_dependency,
1210
OptionalDependency,
11+
runtime_dependency,
1312
)
1413
from ads.dataset import logger
1514

@@ -59,11 +58,10 @@ def on_action_change(change):
5958
if change["type"] == "change" and change["name"] == "value":
6059
if change["new"] == "Fill missing values with constant":
6160
self._show_constant_fill_widget(column)
62-
else:
63-
if change["old"] == "Fill missing values with constant":
64-
text = self.fill_nan_dict.pop(column, None)
65-
if text is not None:
66-
text.close()
61+
elif change["old"] == "Fill missing values with constant":
62+
text = self.fill_nan_dict.pop(column, None)
63+
if text is not None:
64+
text.close()
6765
self.reco_dict[recommendation_type][column]["Selected Action"] = change[
6866
"new"
6967
]
@@ -151,7 +149,6 @@ def show_in_notebook(self):
151149
@runtime_dependency(module="IPython", install_from=OptionalDependency.NOTEBOOK)
152150
@runtime_dependency(module="ipywidgets", install_from=OptionalDependency.NOTEBOOK)
153151
def _display(self):
154-
155152
from IPython.core.display import display
156153

157154
if self.recommendation_type_index != len(self.recommendation_types):
@@ -164,11 +161,7 @@ def _display(self):
164161
]
165162
if self.recommendation_type_index == 0:
166163
for column in recommendation:
167-
print(
168-
"Column '{0}' is constant and will be dropped".format(
169-
column
170-
)
171-
)
164+
print(f"Column '{column}' is constant and will be dropped")
172165
self.recommendation_type_index += 1
173166
self._display()
174167
return
@@ -184,17 +177,17 @@ def _display(self):
184177
self.recommendation_type_labels[
185178
self.recommendation_type_index
186179
]
187-
)
180+
),
181+
layout=ipywidgets.Layout(display="flex"),
188182
),
189-
layout=ipywidgets.Layout(display="flex"),
190183
)
191184
self.action_list[
192185
self.recommendation_types[self.recommendation_type_index]
193186
] = []
194187
self.column_list = []
195188
self.message_list = []
196189
self.extra_info_list = []
197-
for column in recommendation.keys():
190+
for column in recommendation:
198191
messages = ipywidgets.Label(
199192
recommendation[column]["Message"],
200193
layout=ipywidgets.Layout(
@@ -240,9 +233,7 @@ def _display(self):
240233
self.column_list.append(
241234
ipywidgets.Label(
242235
column
243-
+ "(type: {0})".format(
244-
self.ds.sampled_df[column].dtype
245-
),
236+
+ f"(type: {self.ds.sampled_df[column].dtype})",
246237
layout=ipywidgets.Layout(flex="auto"),
247238
color="grey",
248239
)

ads/opctl/operator/lowcode/pii/model/report.py

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
# Copyright (c) 2023, 2024 Oracle and/or its affiliates.
3+
# Copyright (c) 2023, 2025 Oracle and/or its affiliates.
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
55

66

@@ -123,7 +123,6 @@ def make_model_card(model_name="", readme_path=""):
123123
)
124124
return rc.Group(
125125
rc.Text("-"),
126-
columns=1,
127126
)
128127

129128
try:
@@ -156,7 +155,6 @@ def make_model_card(model_name="", readme_path=""):
156155
return rc.Group(
157156
rc.Text(text),
158157
eval_res_tb,
159-
columns=2,
160158
)
161159

162160

@@ -216,7 +214,7 @@ def build_entity_df(entites, id) -> pd.DataFrame:
216214
"Type": "-",
217215
"Redacted To": "-",
218216
}
219-
df = df.append(df2, ignore_index=True)
217+
df = pd.concat([df, pd.DataFrame([df2])], ignore_index=True)
220218
return df
221219

222220

@@ -232,7 +230,6 @@ def build_report(self) -> rc.Group:
232230
self._make_stats_card(),
233231
self._make_text_card(),
234232
],
235-
type=rc.SelectType.TABS,
236233
),
237234
label="Row Id: " + str(self.spec.id),
238235
)
@@ -256,7 +253,7 @@ def _make_stats_card(self):
256253
index=True,
257254
)
258255
)
259-
return rc.Group(stats, label="STATS")
256+
return rc.Group(*stats, label="STATS")
260257

261258
def _make_text_card(self):
262259
annotations = []
@@ -277,7 +274,7 @@ def _make_text_card(self):
277274
},
278275
return_html=True,
279276
)
280-
return rc.Group(rc.HTML(render_html), label="TEXT")
277+
return rc.Group(rc.Html(render_html), label="TEXT")
281278

282279

283280
class PIIOperatorReport:
@@ -292,7 +289,7 @@ def __init__(self, report_spec: PiiReportSpec, report_uri: str):
292289
RowReportFields(r, report_spec.run_summary.show_sensitive_info)
293290
for r in rows
294291
]
295-
292+
self.report_sections = None
296293
self.report_uri = report_uri
297294

298295
def make_view(self):
@@ -317,7 +314,6 @@ def make_view(self):
317314
label="Details",
318315
),
319316
],
320-
type=rc.SelectType.TABS,
321317
)
322318
)
323319
self.report_sections = [title_text, report_description, time_proceed, structure]
@@ -331,7 +327,8 @@ def save_report(
331327
disable_print()
332328
with rc.ReportCreator("My Report") as report:
333329
report.save(
334-
rc.Block(report_sections or self.report_sections), report_local_path
330+
rc.Block(*(report_sections or self.report_sections)),
331+
report_local_path,
335332
)
336333
enable_print()
337334

@@ -354,7 +351,6 @@ def _build_summary_page(self):
354351
self._make_yaml_card(),
355352
self._make_model_card(),
356353
],
357-
type=rc.SelectType.TABS,
358354
),
359355
)
360356

@@ -367,7 +363,6 @@ def _build_details_page(self):
367363
blocks=[
368364
row.build_report() for row in self.rows_details
369365
], # RowReportFields
370-
type=rc.SelectType.DROPDOWN,
371366
label="Details",
372367
),
373368
)
@@ -414,7 +409,6 @@ def _make_summary_stats_card(self) -> rc.Group:
414409
self.report_spec.run_summary.elapsed_time
415410
),
416411
),
417-
columns=2,
418412
),
419413
rc.Heading("Entities Distribution", level=3),
420414
plot_pie(self.report_spec.run_summary.statics),
@@ -423,7 +417,7 @@ def _make_summary_stats_card(self) -> rc.Group:
423417
entites_df = self._build_total_entity_df()
424418
summary_stats.append(rc.Heading("Resolved Entities", level=3))
425419
summary_stats.append(rc.DataTable(entites_df, index=True))
426-
return rc.Group(summary_stats, label="STATS")
420+
return rc.Group(*summary_stats, label="STATS")
427421

428422
def _make_yaml_card(self) -> rc.Group:
429423
"""Shows the full pii config yaml."""
@@ -449,13 +443,12 @@ def _make_model_card(self) -> rc.Group:
449443

450444
if len(model_cards) <= 1:
451445
return rc.Group(
452-
model_cards,
446+
*model_cards,
453447
label="MODEL CARD",
454448
)
455449
return rc.Group(
456450
rc.Select(
457451
model_cards,
458-
type=rc.SelectType.TABS,
459452
),
460453
label="MODEL CARD",
461454
)

0 commit comments

Comments
 (0)