@@ -147,12 +147,17 @@ def fit(
147147 valid ,
148148 )):
149149 this_base_result = base_result | {"i" : i }
150+ error_suffix = f"{ _valid .mean ()= } , { finite_y .mean ()= } , { finite_X .mean ()= } "
150151 this_valid = _valid & finite_y & finite_X
151152 if w is not None :
152- this_valid = this_valid & np .isfinite (w ) & (w > 0. )
153+ finite_w = np .isfinite (w )
154+ nonzero_w = (w > 0. )
155+ this_valid = this_valid & finite_w & nonzero_w
156+ error_suffix += f", { finite_w .mean ()= } , { nonzero_w .mean ()= } "
153157
154- if this_valid .sum () < min_obs :
155- results .append (this_base_result )
158+ n_valid_obs = this_valid .sum ()
159+ if n_valid_obs < min_obs :
160+ results .append (this_base_result | {"fit_status" : f"fail:{ n_valid_obs = } < { min_obs = } ; { error_suffix } " })
156161 _preds .append ((np .array ([]), np .full (x .shape , np .nan ), np .full (x .shape , np .nan )))
157162 continue
158163 if groups is None :
@@ -188,6 +193,10 @@ def fit(
188193 np .stack ([_y for _ , _y , _ in _preds ]),
189194 np .stack ([_p for _ , _ , _p in _preds ]),
190195 )
196+ all_failed = all (d ["fit_status" ].startswith ("fail" ) for d in results )
197+ if all_failed :
198+ fail_modes = sorted (set (d ["fit_status" ].removeprefix ("fail" ) for d in results if d ["fit_status" ].startswith ("fail" )))
199+ raise ValueError (f"All fits failed: { fail_modes } " )
191200 return results , _preds
192201
193202
0 commit comments