88
99from ydata_profiling .config import Settings
1010from ydata_profiling .model .correlations import perform_check_correlation
11- from ydata_profiling .model .var_description .default import VarDescription
11+ from ydata_profiling .model .var_description .default import (
12+ VarDescription ,
13+ VarDescriptionHashable ,
14+ )
1215
1316
1417def fmt_percent (value : float , edge_cases : bool = True ) -> str :
@@ -163,7 +166,7 @@ def _get_description(self) -> str:
163166class ConstantAlert (Alert ):
164167 def __init__ (
165168 self ,
166- values : VarDescription ,
169+ values : VarDescriptionHashable ,
167170 column_name : Optional [str ] = None ,
168171 is_empty : bool = False ,
169172 ):
@@ -221,7 +224,7 @@ def _get_description(self) -> str:
221224class HighCardinalityAlert (Alert ):
222225 def __init__ (
223226 self ,
224- values : VarDescription ,
227+ values : VarDescriptionHashable ,
225228 column_name : Optional [str ] = None ,
226229 is_empty : bool = False ,
227230 ):
@@ -429,7 +432,7 @@ def _get_description(self) -> str:
429432class UniqueAlert (Alert ):
430433 def __init__ (
431434 self ,
432- values : VarDescription ,
435+ values : VarDescriptionHashable ,
433436 column_name : Optional [str ] = None ,
434437 is_empty : bool = False ,
435438 ):
@@ -532,7 +535,7 @@ def check_table_alerts(table: dict) -> List[Alert]:
532535 return alerts
533536
534537
535- def numeric_alerts (config : Settings , summary : VarDescription ) -> List [Alert ]:
538+ def numeric_alerts (config : Settings , summary : VarDescriptionHashable ) -> List [Alert ]:
536539 alerts : List [Alert ] = []
537540
538541 # Skewness
@@ -556,7 +559,7 @@ def numeric_alerts(config: Settings, summary: VarDescription) -> List[Alert]:
556559 return alerts
557560
558561
559- def timeseries_alerts (config : Settings , summary : VarDescription ) -> List [Alert ]:
562+ def timeseries_alerts (config : Settings , summary : VarDescriptionHashable ) -> List [Alert ]:
560563 alerts : List [Alert ] = numeric_alerts (config , summary )
561564
562565 if not summary ["stationary" ]:
@@ -568,7 +571,9 @@ def timeseries_alerts(config: Settings, summary: VarDescription) -> List[Alert]:
568571 return alerts
569572
570573
571- def categorical_alerts (config : Settings , summary : VarDescription ) -> List [Alert ]:
574+ def categorical_alerts (
575+ config : Settings , summary : VarDescriptionHashable
576+ ) -> List [Alert ]:
572577 alerts : List [Alert ] = []
573578
574579 # High cardinality
@@ -597,7 +602,7 @@ def categorical_alerts(config: Settings, summary: VarDescription) -> List[Alert]
597602 return alerts
598603
599604
600- def boolean_alerts (config : Settings , summary : VarDescription ) -> List [Alert ]:
605+ def boolean_alerts (config : Settings , summary : VarDescriptionHashable ) -> List [Alert ]:
601606 alerts : List [Alert ] = []
602607
603608 if (
@@ -618,7 +623,7 @@ def generic_alerts(summary: VarDescription) -> List[Alert]:
618623 return alerts
619624
620625
621- def supported_alerts (summary : VarDescription ) -> List [Alert ]:
626+ def supported_alerts (summary : VarDescriptionHashable ) -> List [Alert ]:
622627 alerts : List [Alert ] = []
623628
624629 if summary .n_distinct == summary .n :
@@ -637,7 +642,7 @@ def unsupported_alerts(summary: VarDescription) -> List[Alert]:
637642
638643
639644def check_variable_alerts (
640- config : Settings , col : str , description : VarDescription
645+ config : Settings , col : str , description : VarDescription | VarDescriptionHashable
641646) -> List [Alert ]:
642647 """Checks individual variables for alerts.
643648
@@ -654,7 +659,7 @@ def check_variable_alerts(
654659
655660 if description ["type" ] == "Unsupported" :
656661 alerts += unsupported_alerts (description )
657- else :
662+ elif isinstance ( description , VarDescriptionHashable ) :
658663 alerts += supported_alerts (description )
659664
660665 if description ["type" ] == "Categorical" :
@@ -665,6 +670,8 @@ def check_variable_alerts(
665670 alerts += timeseries_alerts (config , description )
666671 if description ["type" ] == "Boolean" :
667672 alerts += boolean_alerts (config , description )
673+ else :
674+ raise ValueError ("description should be 'VarDescriptionHashable'" )
668675
669676 for idx in range (len (alerts )):
670677 alerts [idx ].column_name = col
0 commit comments