@@ -72,8 +72,6 @@ def wrapper(
7272 directional_variables : List [str ] = [],
7373 custom_scale_factor : dict = {},
7474 ):
75- # NOTE: Default custom scale factors are defined below
76- _default_custom_scale_factor = {}
7775 if data is None :
7876 raise ValueError ("Data cannot be None" )
7977 elif not isinstance (data , pd .DataFrame ):
@@ -82,19 +80,6 @@ def wrapper(
8280 raise TypeError ("Directional variables must be a list" )
8381 if not isinstance (custom_scale_factor , dict ):
8482 raise TypeError ("Custom scale factor must be a dict" )
85- for directional_variable in directional_variables :
86- if directional_variable not in custom_scale_factor :
87- if directional_variable in _default_custom_scale_factor :
88- custom_scale_factor [directional_variable ] = (
89- _default_custom_scale_factor [directional_variable ]
90- )
91- self .logger .warning (
92- f"Using default custom scale factor for { directional_variable } "
93- )
94- else :
95- self .logger .warning (
96- f"No custom scale factor provided for { directional_variable } , min and max values will be used"
97- )
9883 return func (self , data , directional_variables , custom_scale_factor )
9984
10085 return wrapper
@@ -119,11 +104,9 @@ def validate_data_kma(func):
119104 def wrapper (
120105 self ,
121106 data : pd .DataFrame ,
122- directional_variables : List [str ],
123- custom_scale_factor : dict ,
107+ directional_variables : List [str ] = [] ,
108+ custom_scale_factor : dict = {} ,
124109 ):
125- # NOTE: Default custom scale factors are defined below
126- _default_custom_scale_factor = {}
127110 if data is None :
128111 raise ValueError ("Data cannot be None" )
129112 elif not isinstance (data , pd .DataFrame ):
@@ -132,24 +115,46 @@ def wrapper(
132115 raise TypeError ("Directional variables must be a list" )
133116 if not isinstance (custom_scale_factor , dict ):
134117 raise TypeError ("Custom scale factor must be a dict" )
135- for directional_variable in directional_variables :
136- if directional_variable not in custom_scale_factor :
137- if directional_variable in _default_custom_scale_factor :
138- custom_scale_factor [directional_variable ] = (
139- _default_custom_scale_factor [directional_variable ]
140- )
141- self .logger .warning (
142- f"Using default custom scale factor for { directional_variable } "
143- )
144- else :
145- self .logger .warning (
146- f"No custom scale factor provided for { directional_variable } , min and max values will be used"
147- )
148118 return func (self , data , directional_variables , custom_scale_factor )
149119
150120 return wrapper
151121
152122
123+ def validate_data_som (func ):
124+ """
125+ Decorator to validate data in SOM class fit method.
126+
127+ Parameters
128+ ----------
129+ func : callable
130+ The function to be decorated
131+
132+ Returns
133+ -------
134+ callable
135+ The decorated function
136+ """
137+
138+ @functools .wraps (func )
139+ def wrapper (
140+ self ,
141+ data : pd .DataFrame ,
142+ directional_variables : List [str ] = [],
143+ num_iteration : int = 1000 ,
144+ ):
145+ if data is None :
146+ raise ValueError ("Data cannot be None" )
147+ elif not isinstance (data , pd .DataFrame ):
148+ raise TypeError ("Data must be a pandas DataFrame" )
149+ if not isinstance (directional_variables , list ):
150+ raise TypeError ("Directional variables must be a list" )
151+ if not isinstance (num_iteration , int ) or num_iteration <= 0 :
152+ raise ValueError ("Number of iterations must be integer and > 0" )
153+ return func (self , data , directional_variables , num_iteration )
154+
155+ return wrapper
156+
157+
153158def validate_data_pca (func ):
154159 """
155160 Decorator to validate data in PCA class fit method.
0 commit comments