Skip to content

Commit 16ae12a

Browse files
authored
Merge pull request #369 from bashtage/improve-error
ENH: Improve error for unequal data size
2 parents a8b9362 + 61458c0 commit 16ae12a

File tree

6 files changed

+41
-14
lines changed

6 files changed

+41
-14
lines changed

ci/azure_template_posix.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ jobs:
4242
python39_no_cython:
4343
python.version: '3.9'
4444
SETUP_OPTIONS: '--no-binary'
45-
python39_latest:
45+
python39_recent:
4646
python.version: '3.9'
47+
NUMPY: 1.20.3
48+
SCIPY: 1.6.3
49+
PANDAS: 1.2.5
50+
STATSMODELS: 0.12.2
51+
XARRAY: 0.18.2
52+
python310_latest:
53+
python.version: '3.10'
4754
maxParallel: 10
4855

4956
steps:

doc/source/changes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
Change Log
22
==========
3+
34
Version 4.25
45
------------
6+
* Clarified the null in the F-statistic
7+
* Improved the error message when dependent and exog have different numbers
8+
of observations
9+
* Added formulaic as the preferred formula parser
10+
* Fixed a bug in :class:`~linearmodels.panel.covariance.ACCovariance` estimator where the number of observations
11+
was incorrectly overwritten
512
* Fixed a bug in :func:`linearmodels.panel.results.PanelResults.corr_squared_between`,
613
:func:`linearmodels.panel.results.PanelResults.corr_squared_overall`, and
714
:func:`linearmodels.panel.results.PanelResults.corr_squared_within` where the correlation

linearmodels/panel/model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ def _validate_data(self) -> None:
420420
w = self._w = cast(Float64Array, self.weights.values2d)
421421
if y.shape[0] != x.shape[0]:
422422
raise ValueError(
423-
"dependent and exog must have the same number of " "observations."
423+
"dependent and exog must have the same number of "
424+
"observations. The number of observations in dependent "
425+
f"is {y.shape[0]}, and the number of observations in exog "
426+
f"is {x.shape[0]}."
424427
)
425428
if y.shape[0] != w.shape[0]:
426429
raise ValueError(

linearmodels/tests/panel/_utility.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
from __future__ import annotations
2+
13
import numpy as np
24
from numpy.linalg import lstsq
3-
from numpy.random import standard_normal
5+
from numpy.random import RandomState, standard_normal
46
from numpy.testing import assert_allclose
57
from pandas import Categorical, DataFrame, date_range, get_dummies
68
from pandas.testing import assert_frame_equal, assert_series_equal
79

810
from linearmodels.panel.data import PanelData
911
from linearmodels.shared.utility import AttrDict, panel_to_frame
12+
from linearmodels.typing import Literal
1013

1114
try:
1215
import xarray # noqa: F401
@@ -64,13 +67,13 @@ def lsdv(
6467

6568

6669
def generate_data(
67-
missing,
68-
datatype,
69-
const=False,
70-
ntk=(971, 7, 5),
71-
other_effects=0,
72-
rng=None,
73-
num_cats=4,
70+
missing: bool,
71+
datatype: Literal["pandas", "xarray", "numpy"],
72+
const: bool = False,
73+
ntk: tuple[int, int, int] = (971, 7, 5),
74+
other_effects: int = 0,
75+
rng: RandomState | None = None,
76+
num_cats: int = 4,
7477
):
7578
if rng is None:
7679
np.random.seed(12345)

linearmodels/tests/panel/test_pooled_ols.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,9 @@ def test_alt_cov(data, cov_type):
250250
else:
251251
cov_name = "Driscoll-Kraay"
252252
assert cov_name in str(res.summary)
253+
254+
255+
def test_uneuqal_samples():
256+
data = generate_data(False, "pandas")
257+
with pytest.raises(ValueError, match="dependent and exog must have"):
258+
PooledOLS(data.y.iloc[::2], data.x)

pyproject.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ requires = [
66
"numpy==1.15.4; python_version=='3.7'",
77
"numpy==1.17.5; python_version=='3.8'",
88
"numpy==1.19.5; python_version=='3.9'",
9-
"numpy; python_version>'3.9'",
10-
"Cython>=0.29.22"]
9+
"numpy==1.21.4; python_version=='3.10'",
10+
"numpy; python_version>'3.10'",
11+
"Cython>=0.29.24"]
1112

1213
[tool.black]
13-
target-version = ['py37', 'py38']
14+
target-version = ['py37', 'py38', 'py39']
1415
exclude = '''
1516
(
1617
\.egg
@@ -22,4 +23,4 @@ exclude = '''
2223
| build
2324
| dist
2425
)
25-
'''
26+
'''

0 commit comments

Comments
 (0)