1515
1616import commonmark
1717import narwhals as nw
18- from great_tables import GT , from_column , google_font , html , loc , style , vals
18+ from great_tables import GT , from_column , google_font , html , loc , md , style , vals
1919from importlib_resources import files
2020from narwhals .typing import FrameT
2121
@@ -7551,7 +7551,7 @@ def get_tabular_report(
75517551
75527552 return gt_tbl
75537553
7554- def get_step_report (self , i : int , limit : int | None = 10 ) -> GT :
7554+ def get_step_report (self , i : int , header : str = ":default:" , limit : int | None = 10 ) -> GT :
75557555 """
75567556 Get a detailed report for a single validation step.
75577557
@@ -7569,6 +7569,11 @@ def get_step_report(self, i: int, limit: int | None = 10) -> GT:
75697569 ----------
75707570 i
75717571 The step number for which to get the report.
7572+ header
7573+ Options for customizing the header of the step report. The default is the `":default:"`
7574+ value which produces a generic header. Aside from this default, text can be provided for
7575+ the header. This will be interpreted as Markdown text and transformed internally to
7576+ HTML.
75727577 limit
75737578 The number of rows to display for those validation steps that check values in rows (the
75747579 `col_vals_*()` validation steps). The default is `10` rows and the limit can be removed
@@ -7713,6 +7718,7 @@ def get_step_report(self, i: int, limit: int | None = 10) -> GT:
77137718 all_passed = all_passed ,
77147719 extract = extract ,
77157720 tbl_preview = tbl_preview ,
7721+ header = header ,
77167722 limit = limit ,
77177723 )
77187724
@@ -7726,13 +7732,13 @@ def get_step_report(self, i: int, limit: int | None = 10) -> GT:
77267732 # CASE I: where ordering of columns is required (`in_order=True`)
77277733 if in_order :
77287734 step_report = _step_report_schema_in_order (
7729- step = i , schema_info = val_info , debug_return_df = debug_return_df
7735+ step = i , schema_info = val_info , header = header , debug_return_df = debug_return_df
77307736 )
77317737
77327738 # CASE II: where ordering of columns is not required (`in_order=False`)
77337739 if not in_order :
77347740 step_report = _step_report_schema_any_order (
7735- step = i , schema_info = val_info , debug_return_df = debug_return_df
7741+ step = i , schema_info = val_info , header = header , debug_return_df = debug_return_df
77367742 )
77377743
77387744 else :
@@ -8731,6 +8737,7 @@ def _step_report_row_based(
87318737 all_passed : bool ,
87328738 extract : any ,
87338739 tbl_preview : GT ,
8740+ header : str ,
87348741 limit : int | None ,
87358742):
87368743 # Get the length of the extracted data for the step
@@ -8771,8 +8778,27 @@ def _step_report_row_based(
87718778 text = f"<code style='color: #303030; font-family: monospace; font-size: smaller;'>{ column } </code> is not <code style='color: #303030; font-family: monospace; font-size: smaller;'>Null</code>"
87728779
87738780 if all_passed :
8774- step_report = (
8775- tbl_preview .tab_header (
8781+ step_report = tbl_preview .tab_style (
8782+ style = [
8783+ style .text (color = "#006400" ),
8784+ style .fill (color = "#4CA64C33" ),
8785+ style .borders (
8786+ sides = ["left" , "right" ],
8787+ color = "#1B4D3E80" ,
8788+ style = "solid" ,
8789+ weight = "2px" ,
8790+ ),
8791+ ],
8792+ locations = loc .body (columns = column ),
8793+ ).tab_style (
8794+ style = style .borders (
8795+ sides = ["left" , "right" ], color = "#1B4D3E80" , style = "solid" , weight = "2px"
8796+ ),
8797+ locations = loc .column_labels (columns = column ),
8798+ )
8799+
8800+ if header == ":default:" :
8801+ step_report = step_report .tab_header (
87768802 title = html (f"Report for Validation Step { i } { CHECK_MARK_SPAN } " ),
87778803 subtitle = html (
87788804 "<div>"
@@ -8785,26 +8811,11 @@ def _step_report_row_based(
87858811 "</div></div>"
87868812 ),
87878813 )
8788- .tab_style (
8789- style = [
8790- style .text (color = "#006400" ),
8791- style .fill (color = "#4CA64C33" ),
8792- style .borders (
8793- sides = ["left" , "right" ],
8794- color = "#1B4D3E80" ,
8795- style = "solid" ,
8796- weight = "2px" ,
8797- ),
8798- ],
8799- locations = loc .body (columns = column ),
8800- )
8801- .tab_style (
8802- style = style .borders (
8803- sides = ["left" , "right" ], color = "#1B4D3E80" , style = "solid" , weight = "2px"
8804- ),
8805- locations = loc .column_labels (columns = column ),
8814+
8815+ else :
8816+ step_report = step_report .tab_header (
8817+ title = md (header ),
88068818 )
8807- )
88088819
88098820 else :
88108821 if limit is None :
@@ -8828,8 +8839,22 @@ def _step_report_row_based(
88288839 extract_length_resolved = extract_length
88298840 extract_of_x_rows = "ALL"
88308841
8831- step_report = (
8832- extract_tbl .tab_header (
8842+ step_report = extract_tbl .tab_style (
8843+ style = [
8844+ style .text (color = "#B22222" ),
8845+ style .fill (color = "#FFC1C159" ),
8846+ style .borders (sides = ["left" , "right" ], color = "black" , style = "solid" , weight = "2px" ),
8847+ ],
8848+ locations = loc .body (columns = column ),
8849+ ).tab_style (
8850+ style = style .borders (
8851+ sides = ["left" , "right" ], color = "black" , style = "solid" , weight = "2px"
8852+ ),
8853+ locations = loc .column_labels (columns = column ),
8854+ )
8855+
8856+ if header == ":default:" :
8857+ step_report = step_report .tab_header (
88338858 title = f"Report for Validation Step { i } " ,
88348859 subtitle = html (
88358860 "<div>"
@@ -8845,29 +8870,17 @@ def _step_report_row_based(
88458870 "</div></div>"
88468871 ),
88478872 )
8848- .tab_style (
8849- style = [
8850- style .text (color = "#B22222" ),
8851- style .fill (color = "#FFC1C159" ),
8852- style .borders (
8853- sides = ["left" , "right" ], color = "black" , style = "solid" , weight = "2px"
8854- ),
8855- ],
8856- locations = loc .body (columns = column ),
8857- )
8858- .tab_style (
8859- style = style .borders (
8860- sides = ["left" , "right" ], color = "black" , style = "solid" , weight = "2px"
8861- ),
8862- locations = loc .column_labels (columns = column ),
8873+
8874+ else :
8875+ step_report = step_report .tab_header (
8876+ title = md (header ),
88638877 )
8864- )
88658878
88668879 return step_report
88678880
88688881
88698882def _step_report_schema_in_order (
8870- step : int , schema_info : dict , debug_return_df : bool = False
8883+ step : int , schema_info : dict , header : str , debug_return_df : bool = False
88718884) -> GT | any :
88728885 """
88738886 This is the case for schema validation where the schema is supposed to have the same column
@@ -9045,10 +9058,6 @@ def _step_report_schema_in_order(
90459058
90469059 step_report = (
90479060 GT (schema_combined , id = "pb_step_tbl" )
9048- .tab_header (
9049- title = html (f"Report for Validation Step { step } { passing_symbol } " ),
9050- subtitle = html (col_schema_match_params_html ),
9051- )
90529061 .fmt_markdown (columns = None )
90539062 .opt_table_font (font = google_font (name = "IBM Plex Sans" ))
90549063 .opt_align_table_header (align = "left" )
@@ -9135,6 +9144,15 @@ def _step_report_schema_in_order(
91359144 .tab_options (source_notes_font_size = "12px" )
91369145 )
91379146
9147+ if header == ":default:" :
9148+ step_report = step_report .tab_header (
9149+ title = html (f"Report for Validation Step { step } { passing_symbol } " ),
9150+ subtitle = html (col_schema_match_params_html ),
9151+ )
9152+
9153+ else :
9154+ step_report = step_report .tab_header (title = md (header ))
9155+
91389156 if schema_length == "shorter" :
91399157 # Add background color to the missing column on the exp side
91409158 step_report = step_report .tab_style (
@@ -9179,7 +9197,7 @@ def _step_report_schema_in_order(
91799197
91809198
91819199def _step_report_schema_any_order (
9182- step : int , schema_info : dict , debug_return_df : bool = False
9200+ step : int , schema_info : dict , header : str , debug_return_df : bool = False
91839201) -> GT | any :
91849202 """
91859203 This is the case for schema validation where the schema is permitted to not have to be in the
@@ -9459,10 +9477,6 @@ def _step_report_schema_any_order(
94599477
94609478 step_report = (
94619479 GT (schema_combined , id = "pb_step_tbl" )
9462- .tab_header (
9463- title = html (f"Report for Validation Step { step } { passing_symbol } " ),
9464- subtitle = html (col_schema_match_params_html ),
9465- )
94669480 .fmt_markdown (columns = None )
94679481 .opt_table_font (font = google_font (name = "IBM Plex Sans" ))
94689482 .opt_align_table_header (align = "left" )
@@ -9550,6 +9564,15 @@ def _step_report_schema_any_order(
95509564 .tab_options (source_notes_font_size = "12px" )
95519565 )
95529566
9567+ if header == ":default:" :
9568+ step_report = step_report .tab_header (
9569+ title = html (f"Report for Validation Step { step } { passing_symbol } " ),
9570+ subtitle = html (col_schema_match_params_html ),
9571+ )
9572+
9573+ else :
9574+ step_report = step_report .tab_header (title = md (header ))
9575+
95539576 # Add background color to signify limits of target table schema (on LHS side)
95549577 if len (colnames_exp_unmatched ) > 0 :
95559578 step_report = step_report .tab_style (
0 commit comments