@@ -86,6 +86,10 @@ class Input:
8686 :py:attr:`data`, insert this value. Defaults to NaN, in which case the impact
8787 from the model is ignored. Set this to zero to explicitly calibrate to zero
8888 impacts in these cases.
89+ df_to_numpy : Callable
90+ A function that transforms a pandas.DataFrame into a numpy.ndarray to be
91+ inserted into the :py:attr:`cost_func`. By default, this will flatten the data
92+ frame.
8993 data_weights : pandas.DataFrame, optional
9094 Weights for each entry in :py:attr:`data`. Must have the exact same index and
9195 columns. If ``None``, the weights will be ignored (equivalent to the same weight
@@ -109,6 +113,9 @@ class Input:
109113 default_factory = lambda : {"assign_centroids" : False }
110114 )
111115 missing_data_value : float = np .nan
116+ df_to_numpy : Callable [[pd .DataFrame ], np .ndarray ] = (
117+ lambda df : df .to_numpy ().flatten ()
118+ )
112119 data_weights : pd .DataFrame | None = field (default = None , kw_only = True )
113120 missing_weights_value : float = field (default = 0.0 , kw_only = True )
114121 assign_centroids : InitVar [bool ] = field (default = True , kw_only = True )
@@ -523,12 +530,12 @@ def _opt_func(self, *args, **kwargs) -> Number:
523530 copy = True ,
524531 fill_value = self .input .missing_weights_value ,
525532 )
526- weights_aligned = weights_aligned . to_numpy (). flatten ( )
533+ weights_aligned = self . input . df_to_numpy ( weights_aligned )
527534
528535 # Compute target function
529536 return self ._target_func (
530- data_aligned . to_numpy (). flatten ( ),
531- impact_df_aligned . to_numpy (). flatten ( ),
537+ self . input . df_to_numpy ( data_aligned ),
538+ self . input . df_to_numpy ( impact_df_aligned ),
532539 weights_aligned ,
533540 )
534541
0 commit comments