diff --git a/linearmodels/system/model.py b/linearmodels/system/model.py index dd07ead7d9..2b9727bf22 100644 --- a/linearmodels/system/model.py +++ b/linearmodels/system/model.py @@ -102,7 +102,7 @@ def _missing_weights( missing = [key for key in weights if weights[key] is None] if missing: msg = "Weights not found for equation labels:\n{}".format(", ".join(missing)) - warnings.warn(msg, UserWarning) + warnings.warn(msg, UserWarning, stacklevel=2) def _parameters_from_xprod( @@ -1917,6 +1917,7 @@ def __init__( "matrix not unadjusted (homoskedastic). sigma will " "be ignored.", UserWarning, + stacklevel=1, ) weight_type = COV_TYPES[weight_type] self._weight_est = GMM_W_EST[weight_type](**weight_config) diff --git a/linearmodels/tests/panel/_utility.py b/linearmodels/tests/panel/_utility.py index 8a4423e1ad..36f2d47be0 100644 --- a/linearmodels/tests/panel/_utility.py +++ b/linearmodels/tests/panel/_utility.py @@ -200,13 +200,23 @@ def generate_data( def assert_results_equal(res1, res2, test_fit=True, test_df=True, strict=True): + from pandas import Index + + def fix_index(x: Series | DataFrame, n: int): + if isinstance(x, Series): + out = x.iloc[:n].copy() + else: + out = x.iloc[:n, :n].copy() + out.index = Index(out.index.to_list()) + return out + n = min(res1.params.shape[0], res2.params.shape[0]) - assert_series_equal(res1.params.iloc[:n], res2.params.iloc[:n]) - assert_series_equal(res1.pvalues.iloc[:n], res2.pvalues.iloc[:n]) - assert_series_equal(res1.tstats.iloc[:n], res2.tstats.iloc[:n]) - assert_frame_equal(res1.cov.iloc[:n, :n], res2.cov.iloc[:n, :n]) - assert_frame_equal(res1.conf_int().iloc[:n], res2.conf_int().iloc[:n]) + assert_series_equal(res1.params.iloc[:n], fix_index(res2.params, n)) + assert_series_equal(res1.pvalues.iloc[:n], fix_index(res2.pvalues, n)) + assert_series_equal(res1.tstats.iloc[:n], fix_index(res2.tstats, n)) + assert_frame_equal(res1.cov.iloc[:n, :n], fix_index(res2.cov, n)) + assert_frame_equal(res1.conf_int().iloc[:n], fix_index(res2.conf_int(), n)) assert_allclose(res1.s2, res2.s2) diff --git a/linearmodels/tests/panel/test_panel_ols.py b/linearmodels/tests/panel/test_panel_ols.py index 50995fa569..06b2cafb69 100644 --- a/linearmodels/tests/panel/test_panel_ols.py +++ b/linearmodels/tests/panel/test_panel_ols.py @@ -286,7 +286,9 @@ def test_panel_entity_lsdv(data): d_demean = d.values xd = np.c_[x.values, d_demean] - xd = pd.DataFrame(xd, index=x.index, columns=list(x.columns) + list(d.columns)) + xd = pd.DataFrame( + xd, index=x.index, columns=list(x.columns) + [f"fe_{col}" for col in d.columns] + ) ols_mod = IV2SLS(y, xd, None, None) res2 = ols_mod.fit(cov_type="unadjusted", debiased=False) @@ -388,7 +390,9 @@ def test_panel_time_lsdv(large_data): d = d - z @ lstsq(z, d, rcond=None)[0] xd = np.c_[x.values, d] - xd = pd.DataFrame(xd, index=x.index, columns=list(x.columns) + d_cols) + xd = pd.DataFrame( + xd, index=x.index, columns=list(x.columns) + [f"fe_{col}" for col in d_cols] + ) ols_mod = IV2SLS(y, xd, None, None) res2 = ols_mod.fit(cov_type="unadjusted") @@ -490,7 +494,11 @@ def test_panel_both_lsdv(data): xd = np.c_[x.values, d] xd = pd.DataFrame( - xd, index=x.index, columns=list(x.columns) + list(d1.columns) + list(d2.columns) + xd, + index=x.index, + columns=list(x.columns) + + [f"fe_{col}" for col in d1.columns] + + [f"te_{col}" for col in d2.columns], ) ols_mod = IV2SLS(y, xd, None, None) @@ -597,7 +605,9 @@ def test_panel_entity_lsdv_weighted(data): d = d - z @ lstsq(wz, wd, rcond=None)[0] xd = np.c_[x.values, d] - xd = pd.DataFrame(xd, index=x.index, columns=list(x.columns) + list(d_cols)) + xd = pd.DataFrame( + xd, index=x.index, columns=list(x.columns) + [f"fe_{col}" for col in d_cols] + ) ols_mod = IV2SLS(y, xd, None, None, weights=w) res2 = ols_mod.fit(cov_type="unadjusted") @@ -677,7 +687,9 @@ def test_panel_time_lsdv_weighted(large_data): d = d - z @ lstsq(wz, wd, rcond=None)[0] xd = np.c_[x.values, d] - xd = pd.DataFrame(xd, index=x.index, columns=list(x.columns) + list(d_cols)) + xd = pd.DataFrame( + xd, index=x.index, columns=list(x.columns) + [f"te_{col}" for col in d_cols] + ) ols_mod = IV2SLS(y, xd, None, None, weights=w) res2 = ols_mod.fit(cov_type="unadjusted") @@ -760,7 +772,11 @@ def test_panel_both_lsdv_weighted(data): xd = np.c_[x.values, d] xd = pd.DataFrame( - xd, index=x.index, columns=list(x.columns) + list(d1.columns) + list(d2.columns) + xd, + index=x.index, + columns=list(x.columns) + + [f"fe_{col}" for col in d1.columns] + + [f"te_{col}" for col in d2.columns], ) ols_mod = IV2SLS(y, xd, None, None, weights=w)