Skip to content

ENH/BUG: Add check to AR instance to prevent bugs - #5997

Merged
bashtage merged 1 commit into
statsmodels:masterfrom
bashtage:check-ar-arma-arima-mutation
Jul 24, 2019
Merged

bashtage merged 1 commit into
statsmodels:masterfrom
bashtage:check-ar-arma-arima-mutation

Conversation

@bashtage

@bashtage bashtage commented Jul 22, 2019 •

Copy link
Copy Markdown
Member

Prevent refit except in cases where it does not break results instances
Complete testing of AR
Clean files

Details

Notes:

  • It is essential that you add a test when making code changes. Tests are not
    needed for doc changes.
  • When adding a new function, test values should usually be verified in another package (e.g., R/SAS/Stata).
  • When fixing a bug, you must add a test that would produce the bug in master and
    then show that it is fixed with the new code.
  • New code additions must be well formatted. Changes should pass flake8. If on Linux or OSX, you can
    verify you changes are well formatted by running
    git diff upstream/master -u -- "*.py" | flake8 --diff --isolated
    
    assuming flake8 is installed. This command is also available on Windows
    using the Windows System for Linux once flake8 is installed in the
    local Linux environment. While passing this test is not required, it is good practice and it help
    improve code quality in statsmodels.
  • Docstring additions must render correctly, including escapes and LaTeX.

@pep8speaks

pep8speaks commented Jul 22, 2019 •

Copy link
Copy Markdown

Hello @bashtage! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 304:30: W503 line break before binary operator
Line 749:17: W503 line break before binary operator

Line 224:65: W504 line break after binary operator
Line 226:23: W503 line break before binary operator

Comment last updated at 2019-07-24 10:04:53 UTC

@coveralls

coveralls commented Jul 22, 2019 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 85.903% when pulling ab0f955 on bashtage:check-ar-arma-arima-mutation into 21910ef on statsmodels:master.

@codecov

codecov Bot commented Jul 22, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #5997 into master will increase coverage by 0.13%.
The diff coverage is 99.59%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5997      +/-   ##
==========================================
+ Coverage   83.28%   83.42%   +0.13%     
==========================================
  Files         606      606              
  Lines       95121    95375     +254     
  Branches    10393    10396       +3     
==========================================
+ Hits        79221    79563     +342     
+ Misses      13519    13445      -74     
+ Partials     2381     2367      -14
Impacted Files Coverage Δ
statsmodels/tsa/tests/test_arima.py 99.51% <ø> (+0.06%) ⬆️
statsmodels/tools/validation/validation.py 98.55% <100%> (+0.02%) ⬆️
statsmodels/tsa/ar_model.py 99.18% <100%> (+6.3%) ⬆️
statsmodels/tsa/tests/test_ar.py 100% <100%> (ø) ⬆️
statsmodels/tsa/arima_model.py 94.04% <98.88%> (+7.63%) ⬆️
statsmodels/tsa/base/tsa_model.py 87.94% <0%> (+0.89%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21910ef...ab0f955. Read the comment docs.

@bashtage
bashtage force-pushed the check-ar-arma-arima-mutation branch 2 times, most recently from 976b009 to dc2438b Compare July 22, 2019 16:16
@jbrockmendel

Copy link
Copy Markdown
Contributor

Looks promising. I’ll do a proper review tomorrow.

@bashtage
bashtage force-pushed the check-ar-arma-arima-mutation branch 2 times, most recently from 7d0f387 to 1befbc6 Compare July 23, 2019 07:52
@bashtage
bashtage force-pushed the check-ar-arma-arima-mutation branch 6 times, most recently from a600542 to ea4dfd2 Compare July 23, 2019 22:40
Comment thread statsmodels/tsa/ar_model.py Resolved
Comment thread statsmodels/tsa/ar_model.py Resolved
Comment thread statsmodels/tsa/ar_model.py Resolved
Comment thread statsmodels/tsa/ar_model.py Resolved
Comment thread statsmodels/tsa/ar_model.py Resolved
Comment thread statsmodels/tsa/ar_model.py Resolved
Comment thread statsmodels/tsa/ar_model.py Resolved
Comment thread statsmodels/tsa/ar_model.py Resolved
Comment thread statsmodels/tsa/ar_model.py Resolved
Comment thread statsmodels/tsa/ar_model.py Resolved
Comment thread statsmodels/tsa/arima_model.py Resolved
Comment thread statsmodels/tsa/arima_model.py Resolved
Comment thread statsmodels/tsa/arima_model.py Resolved
Comment thread statsmodels/tsa/arima_model.py Resolved
Comment thread statsmodels/tsa/arima_model.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
# assert_raises(ValueError, model._get_prediction_index, *(311, None, True))
# assert_raises(ValueError, model._get_prediction_index, *(311, None, False))
# assert_raises(ValueError, model._get_prediction_index, *('2010', None, True))
# assert_raises(ValueError, model._get_prediction_index, *('2010', None, False))

# works - in-sample
# None
start_test_cases = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: pytest.mark.parametrize

Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
Comment thread statsmodels/tsa/tests/test_arima.py Resolved
# make an exogenous trend
# X = np.array(lrange(nobs)) / 20.0
# add a constant
# y += 2.5

from pandas import read_csv

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: just use pd.read_csv, already in the namespace

Comment thread statsmodels/tsa/tests/test_arima.py Resolved
##rkf.params
modkf = ARMA(x, (1, 1))
# rkf = mkf.fit((1,1))
# rkf.params
reskf = modkf.fit(trend='nc', disp=-1)
dres = reskf

modc = Arma(x)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting this into a separate module would be nice, since this Arma class needs to DIAF.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have worked it over more than once, I think the plan forward should be to thinly wrap SARIMAX to produce ARMA and ARIMAX that simplify the inputs (remove seasonal, and integration for ARMA). These will need to live in statespace, and then a FutureWarning can be added to ARMA and ARIMA. Less sure about AR, since a simple OLS AR is very useful for performance.

@jbrockmendel

Copy link
Copy Markdown
Contributor

Generally looks really good. For the commented-out test code if you'll add FIXME markers to it so it doesn't fall through the cracks, I'll try to troubleshoot it in follow-ups.

@bashtage
bashtage force-pushed the check-ar-arma-arima-mutation branch 2 times, most recently from a4830b7 to 0feb0fa Compare July 24, 2019 10:04
Prevent refit except in cases where it does not break results instances

closes statsmodels#3882
closes statsmodels#5985
@bashtage
bashtage force-pushed the check-ar-arma-arima-mutation branch from 0feb0fa to ab0f955 Compare July 24, 2019 10:08
@bashtage
bashtage merged commit 842e779 into statsmodels:master Jul 24, 2019
@bashtage
bashtage deleted the check-ar-arma-arima-mutation branch July 24, 2019 12:13
@jbrockmendel

Copy link
Copy Markdown
Contributor

There are a couple of places in the tests where commented-out code was left behind, I'll address in a follow-up.

What do you think about using this same pattern for VAR?

@bashtage

bashtage commented Aug 2, 2019

Copy link
Copy Markdown
Member Author

I think it is reasonable for VAR as well. I'm slowly working on a new version of VAR with a different name (VectorAR) that doesn't allow mutation. My idea will be to eventually deprecate VAR and redirect users to VectorAR and then once VAR is removed, to alias VectorAR to VAR. Although I'm not sure I'm patient enough to wait the required to do the aliasing (which is probably multiple years), so it might just stay VectorAR forever.

@bashtage bashtage added this to the 0.11 milestone Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: ARMA model is not immutable ARMA.predict()

4 participants