Skip to content

CLN: Flake8 fixups and linting for statespace files (but not tests) - #4842

Merged
ChadFulton merged 2 commits into
statsmodels:masterfrom
jbrockmendel:slint2
Sep 1, 2018
Merged

ChadFulton merged 2 commits into
statsmodels:masterfrom
jbrockmendel:slint2

Conversation

@jbrockmendel

Copy link
Copy Markdown
Contributor

@ChadFulton The statespace files themselves are in pretty good shape, there are are a couple of points I'll comment on inline where your input will be needed in a follow-up.

After this statespace/tests/results/*.py will be an easy PR, then the test files will be split into a few steps because they're in less-good condition than the rest.

Comment thread statsmodels/tsa/statespace/varmax.py Outdated
# If we had exog, then the last predicted_state has been set to NaN
# since we didn't have the appropriate exog to create it. Then, if
# we are purely forecasting,
# we are purely forecasting, TODO: Finish this sentence?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@chad this probably needs your input.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for catching this. How about:

# If we had exog, then the last predicted_state has been set to NaN
# since we didn't have the appropriate exog to create it. Then, if
# we are forecasting, we now have new exog that we need to put into
# the existing state_intercept array (and we will take it out, below)

if not A.is_f_contig():
raise ValueError()
except:
except (AttributeError, ValueError):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ChadFulton I'm fairly confident this is what should be caught, but this merits another pair of eyes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

try:
jb = self.test_normality(method='jarquebera')
except:
except Exception: # FIXME: catch something specific

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ChadFulton This is the next-to-last thing that needs your input.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you think about just # noqa on these? Two reasons:

  • These are in the summary, and I think that we want to show the summary regardless of any errors here.
  • There are a whole host of exceptions that could arise from the class methods or from the functions that they call, so it might be tough to narrow down all of the possible exceptions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

At the very least it should be exception Exception:. With just except: we will e.g. catch KeyboardInterrupt which is definitely undesired.

I'd be OK with leaving the "FIXME" here for the time being. It's a low enough priority that we don't need to fix it immediately, but high enough that it should be hard to ignore on the next pass.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

At the very least it should be exception Exception:. With just except: we will e.g. catch KeyboardInterrupt which is definitely undesired.

Good point.

I'd be OK with leaving the "FIXME" here for the time being. It's a low enough priority that we don't need to fix it immediately, but high enough that it should be hard to ignore on the next pass.

Okay, we can discuss later.

initial_diffuse_state_cov=initial_diffuse_state_cov,
initial_stationary_state_cov=initial_stationary_state_cov)
# TODO: Should something be done with the object returned
# by init?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ChadFulton last thing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, no, I think they're set in place at each recursion. I guess maybe I was originally planning something different. If you don't mind, can you replace:

# Otherwise, if using blocks, combine the elements returned by each of
# the blocks and return those

with:

# Otherwise, if using blocks, recursively initialize them (values will be set in-place)

@coveralls

coveralls commented Aug 7, 2018 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.03%) to 83.897% when pulling 446e123 on jbrockmendel:slint2 into 50c7a5d on statsmodels:master.

@codecov-io

codecov-io commented Aug 7, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #4842 into master will increase coverage by 0.02%.
The diff coverage is 96.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4842      +/-   ##
==========================================
+ Coverage   81.41%   81.44%   +0.02%     
==========================================
  Files         582      582              
  Lines       90312    90113     -199     
  Branches    10108    10094      -14     
==========================================
- Hits        73528    73390     -138     
+ Misses      14485    14421      -64     
- Partials     2299     2302       +3
Impacted Files Coverage Δ
statsmodels/tsa/statespace/_pykalman_smoother.py 0% <ø> (ø) ⬆️
statsmodels/tsa/statespace/representation.py 92.06% <ø> (-0.03%) ⬇️
statsmodels/tsa/statespace/initialization.py 92.04% <100%> (ø) ⬆️
statsmodels/tsa/statespace/structural.py 88.74% <100%> (-0.02%) ⬇️
statsmodels/tsa/statespace/kalman_filter.py 84.21% <100%> (-0.03%) ⬇️
statsmodels/tsa/statespace/api.py 100% <100%> (ø) ⬆️
statsmodels/tsa/statespace/sarimax.py 93.69% <100%> (ø) ⬆️
statsmodels/tsa/statespace/varmax.py 91.21% <100%> (ø) ⬆️
statsmodels/tsa/statespace/tools.py 73.79% <88.88%> (+0.05%) ⬆️
statsmodels/tsa/statespace/mlemodel.py 86% <95%> (ø) ⬆️
... and 7 more

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 50c7a5d...446e123. Read the comment docs.

@ChadFulton ChadFulton changed the title flake8 fixups and linting for statespace files (but not tests) CLN: Flake8 fixups and linting for statespace files (but not tests) Aug 8, 2018
r"""
(array) Transition matrix: :math:`T~(k\_states \times k\_states \times nobs)`
(array) Transition matrix:
:math:`T~(k\_states \times k\_states \times nobs)`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this has to be on one line for Sphinx, not sure if they fixed it though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Other entries are on two lines, e.g. line 234-237 above:

     r"""
     (array) Observation covariance matrix:
     :math:`H~(k\_endog \times k\_endog \times nobs)`
     """

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there a conclusion on what the right thing to do is here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ChadFulton

Copy link
Copy Markdown
Member

Other than those comments, LGTM. Thanks!

@jbrockmendel
jbrockmendel force-pushed the slint2 branch 2 times, most recently from 9f644fa to 75c09e9 Compare August 20, 2018 14:49
@jbrockmendel
jbrockmendel force-pushed the slint2 branch 2 times, most recently from df67a1e to 8091195 Compare August 30, 2018 20:06
@ChadFulton

Copy link
Copy Markdown
Member

@jbrockmendel happy to merge this, but I think there are still a few outstanding changes required.

@jbrockmendel

Copy link
Copy Markdown
Contributor Author

but I think there are still a few outstanding changes required.

Just implemented what I think are the remaining ones. Let me know if I missed anything.

@ChadFulton

Copy link
Copy Markdown
Member

Thanks @jbrockmendel !

@ChadFulton
ChadFulton merged commit 8e6f521 into statsmodels:master Sep 1, 2018
@jbrockmendel
jbrockmendel deleted the slint2 branch September 3, 2018 16:39
@josef-pkt josef-pkt added this to the 0.10 milestone Sep 16, 2018
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.

5 participants