Repository navigation
ENH: KPSS - detailed error message when lags > nobs - #5707
Conversation
bashtage
left a comment
There was a problem hiding this comment.
A few details. Also, could you squash to one since this is a single issue
| lags = int(lags) | ||
|
|
||
| if lags > nobs: | ||
| raise ValueError("lags (%d) must be <= number of observations (%d)" % (lags, nobs)) |
There was a problem hiding this comment.
Could you use modern formatting
|
|
||
| def test_kpss_fails_on_nobs_check(self): | ||
| # Test that if lags exceeds nobs KPSS raises a clear error | ||
| with pytest.raises(ValueError): |
There was a problem hiding this comment.
Could you use match to check the error message
There was a problem hiding this comment.
+1 for this suggestion. Also can you add “GH#5707” to the comment above?
There was a problem hiding this comment.
Great catch, thank you.
jbrockmendel, to clarify, do you mean to add GH#5707 in the test comment (line 539), or to the PR checklist?
There was a problem hiding this comment.
To the comment on line 539. It makes it slightly easier for a curious reader to look up the motivation for the test.
| else: | ||
| lags = int(lags) | ||
|
|
||
| if lags > nobs: |
There was a problem hiding this comment.
What about the number of obs and the included deterministic terms? This is unlikely to bind but could create an error.
There was a problem hiding this comment.
I'm not sure I follow, could you please explain this a little more? My understanding is that the error that occurs when lags exceeds # obs stems from _sigma_est_kpss, particularly:
resids_prod = np.dot(resids[i:], resids[:nobs - i])
Example error with # obs = 3, lags set to 4:
ValueError: shapes (0,) and (2,) not aligned: 0 (dim 0) != 2 (dim 0)
Codecov Report
@@ Coverage Diff @@
## master #5707 +/- ##
==========================================
+ Coverage 82.22% 82.22% +<.01%
==========================================
Files 593 593
Lines 93711 93716 +5
Branches 10352 10353 +1
==========================================
+ Hits 77053 77058 +5
Misses 14257 14257
Partials 2401 2401
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #5707 +/- ##
==========================================
+ Coverage 82.22% 82.22% +<.01%
==========================================
Files 593 593
Lines 93711 93716 +5
Branches 10352 10353 +1
==========================================
+ Hits 77053 77058 +5
Misses 14257 14257
Partials 2401 2401
Continue to review full report at Codecov.
|
|
Thanks. Other point isn't essential. Wondering if it crashes if run on a very short series, e.g., 1 observation. |
CLN: fix invalid escapes in test_stattools introduced in #5707
I don't believe there are open issues for this, but the enhancement is related to #5432 & #3330, only for the KPSS test. Adds a clear error message when the lags parameter exceeds the number of observations.
NumPy's guide.