Skip to content

Commit e37529c

Browse files
committed
BUG: Fix drop selection with weighted and absorbed
Fix slice when selecting variables to drop
1 parent 5ba2bea commit e37529c

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

linearmodels/panel/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1883,7 +1883,7 @@ def fit(
18831883

18841884
# Adjust exog
18851885
self.exog = PanelData(self.exog.dataframe.iloc[:, retain])
1886-
x_effects = x_effects[retain]
1886+
x_effects = x_effects[:, retain]
18871887

18881888
params = _lstsq(x, y, rcond=None)[0]
18891889
nobs = self.dependent.dataframe.shape[0]

linearmodels/tests/panel/test_panel_ols.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pandas as pd
77
import pytest
88

9+
from linearmodels.datasets import wage_panel
910
from linearmodels.iv.model import IV2SLS
1011
from linearmodels.panel.data import PanelData
1112
from linearmodels.panel.model import PanelOLS, PooledOLS
@@ -1531,3 +1532,26 @@ def test_entity_into():
15311532
ti = res.time_info
15321533
assert ti["total"] == 4
15331534
assert ti["min"] == 16
1535+
1536+
1537+
@pytest.mark.parametrize("path", ["use_lsdv", "low_memory"])
1538+
def test_absorbed_with_weights(path):
1539+
data = wage_panel.load().copy()
1540+
year = pd.Categorical(data.year)
1541+
data = data.set_index(["nr", "year"])
1542+
data["year"] = year
1543+
# and random number between 0 and 1 for weights
1544+
data["rand"] = np.random.rand(data.shape[0])
1545+
data["absorbe"] = data.groupby("nr")["union"].transform("mean")
1546+
1547+
fit_options = {}
1548+
if path:
1549+
fit_options[path] = True
1550+
1551+
with pytest.warns(AbsorbingEffectWarning, match="Variables have been"):
1552+
PanelOLS.from_formula(
1553+
"lwage ~1+absorbe + married + EntityEffects",
1554+
data=data,
1555+
weights=data["rand"],
1556+
drop_absorbed=True,
1557+
).fit(**fit_options)

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,13 @@ exclude = '''
2626

2727
[tool.setuptools_scm]
2828
write_to = "linearmodels/_version.py"
29+
30+
[tool.pyright]
31+
exclude = [
32+
"**/tests/**",
33+
]
34+
35+
[tool.mypy]
36+
exclude = [
37+
"tests",
38+
]

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
xarray>=0.16
22
mypy>=1.3
3-
black[jupyter]==23.3.0
3+
black[jupyter]==23.7.0
44
pytest>=7.3.0
55
isort>=5.12
66
ipython
@@ -10,6 +10,7 @@ nbconvert
1010
nbformat
1111
nbsphinx
1212
numpydoc
13+
pandas-stubs
1314
pytest-xdist
1415
pytest-cov
1516
seaborn

requirements-test.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
black[jupyter]==23.3.0
1+
black[jupyter]==23.7.0
22
coverage
33
flake8
44
isort
55
matplotlib
6-
pytest>=7.0,<7.1
6+
pytest>=7.3.0
77
pytest-xdist
88
pytest-cov
99
seaborn

0 commit comments

Comments
 (0)