File tree Expand file tree Collapse file tree 3 files changed +24
-11
lines changed
Expand file tree Collapse file tree 3 files changed +24
-11
lines changed Original file line number Diff line number Diff line change 5050 OneWayClusteredWeightMatrix ,
5151)
5252from linearmodels .iv .results import IVGMMResults , IVResults , OLSResults
53- from linearmodels .panel .utility import InvalidFormulaError
5453from linearmodels .shared .exceptions import IndexWarning , missing_warning
5554from linearmodels .shared .hypotheses import InvalidTestStatistic , WaldTestStatistic
5655from linearmodels .shared .linalg import has_constant , inv_sqrth
@@ -300,11 +299,6 @@ def predict(
300299 parser = IVFormulaParser (self .formula , data , eval_env = eval_env )
301300 exog = parser .exog
302301 endog = parser .endog
303- if exog is None and exog is None :
304- raise InvalidFormulaError (
305- f"Parsed formula ({ self .formula } ) has no exog and no endog. One "
306- f"of these must be included in the formula to make a prediction."
307- )
308302 if all (a is None for a in (exog , endog , data )):
309303 raise ValueError ("At least one of exog, endog, or data must be provided." )
310304 if exog is None :
Original file line number Diff line number Diff line change 2424__all__ = [
2525 "AbsorbingEffectError" ,
2626 "AbsorbingEffectWarning" ,
27- "InvalidFormulaError" ,
2827 "_drop_singletons" ,
2928 "_py_drop_singletons" ,
3029 "_remove_node" ,
@@ -689,7 +688,3 @@ def generate_panel_data(
689688 clusters = concat ([vc1_df , vc2_df ], sort = False )
690689 data = concat ([y_df , x_df ], axis = 1 , sort = False )
691690 return PanelModelData (data , w_df , other_eff , clusters )
692-
693-
694- class InvalidFormulaError (Exception ):
695- pass
Original file line number Diff line number Diff line change @@ -416,3 +416,27 @@ def test_predict_no_rhs(data, model_and_func):
416416 pred1 = res .predict (data = data )
417417 pred1 .columns = pred0 .columns
418418 assert_frame_equal (pred0 , pred1 )
419+
420+
421+ @pytest .mark .parametrize (
422+ "fmla" ,
423+ [
424+ "y ~ 1" ,
425+ "y ~ 1 + x3" ,
426+ "y ~ [x1 + x2 ~ 1 + z1 + z2 + z3]" ,
427+ "y ~ 1 + [x1 + x2 ~ z1 + z2 + z3]" ,
428+ ],
429+ )
430+ def test_formula_single (data , model_and_func , fmla ):
431+ model , func = model_and_func
432+ res = model .from_formula (fmla , data ).fit ()
433+ pred0 = res .predict ()
434+ pred1 = res .predict (data = data )
435+
436+ mod2 = func (fmla , data )
437+ res2 = mod2 .fit ()
438+ pred2 = res2 .predict (data = data )
439+ pred1 .columns = pred0 .columns
440+ pred2 .columns = pred0 .columns
441+ assert_frame_equal (pred1 , pred2 )
442+ assert_frame_equal (pred0 , pred1 )
You can’t perform that action at this time.
0 commit comments