Repository navigation
Conversation
Since the numpy rewrite, _ftr calls sliding_window_view and _sym_wma4 assigns a 'valid' convolution without checking the length, so ftr, rvgi/rvgis and sym_wma4 raise ValueError when there are fewer rows than the window. Return zeros in that case, as before the rewrite; the other windowed helpers already guard short input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since #200 (numpy rewrite),
ftrand the RVGI columns raise on data with fewer rows than their window:_ftrpasses the prices tonp.lib.stride_tricks.sliding_window_viewwithout checking that there are at leastwindowof them._sym_wma4assignsnp.convolve(..., mode="valid")toout[3:]. With fewer than 4 values, numpy swaps the arguments and returns5 - nvalues, which don't fit.Before #200 both returned zeros in this case. The other windowed helpers (
_mad,linear_wma,linear_reg,_inertia) already return early on short input, so this adds a guard to these two. Results for data longer than the window are unchanged.Tests: added
test_ftr_shorter_than_window,test_rvgi_shorter_than_windowandtest_sym_wma4_shorter_than_windowtotest.py. They fail withValueErroronmasterand pass with the fix. The full suite passes (135), andflake8 stockstats.py test.pyis clean.