Skip to content

BUG: rename wts to weights issue #4725 - #5762

Merged
bashtage merged 1 commit into
statsmodels:masterfrom
zverianskii:bugfix_4725
May 22, 2019
Merged

bashtage merged 1 commit into
statsmodels:masterfrom
zverianskii:bugfix_4725

Conversation

@zverianskii

@zverianskii zverianskii commented May 20, 2019 •

Copy link
Copy Markdown
Contributor

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 May 20, 2019 •

Copy link
Copy Markdown

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

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-05-21 12:39:19 UTC

@zverianskii zverianskii changed the title Bugfix #4725 BUG: rename wts to weights issue #4725 May 20, 2019
@coveralls

coveralls commented May 20, 2019 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.05%) to 84.866% when pulling fa6a592 on zveryansky:bugfix_4725 into c8cf0c9 on statsmodels:master.

@codecov

codecov Bot commented May 20, 2019

Copy link
Copy Markdown

Codecov Report

Merging #5762 into master will increase coverage by 0.01%.
The diff coverage is 97.36%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #5762      +/-   ##
=========================================
+ Coverage   82.28%   82.3%   +0.01%     
=========================================
  Files         593     593              
  Lines       93622   93627       +5     
  Branches    10339   10333       -6     
=========================================
+ Hits        77041   77057      +16     
+ Misses      14184   14177       -7     
+ Partials     2397    2393       -4
Impacted Files Coverage Δ
statsmodels/base/tests/test_penalties.py 100% <100%> (ø) ⬆️
statsmodels/base/_penalties.py 82.47% <94.44%> (+3.61%) ⬆️

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 c8cf0c9...4904dd0. Read the comment docs.

@codecov

codecov Bot commented May 20, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #5762 into master will increase coverage by 0.01%.
The diff coverage is 97.36%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #5762      +/-   ##
=========================================
+ Coverage   82.28%   82.3%   +0.01%     
=========================================
  Files         593     593              
  Lines       93622   93627       +5     
  Branches    10339   10333       -6     
=========================================
+ Hits        77041   77057      +16     
+ Misses      14184   14178       -6     
+ Partials     2397    2392       -5
Impacted Files Coverage Δ
statsmodels/base/tests/test_penalties.py 100% <100%> (ø) ⬆️
statsmodels/base/_penalties.py 82.47% <94.44%> (+3.61%) ⬆️
statsmodels/stats/descriptivestats.py 24.34% <0%> (ø) ⬆️

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 c8cf0c9...4904dd0. Read the comment docs.

@codecov

codecov Bot commented May 20, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #5762 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #5762      +/-   ##
=========================================
+ Coverage   82.28%   82.3%   +0.01%     
=========================================
  Files         593     593              
  Lines       93622   93648      +26     
  Branches    10339   10339              
=========================================
+ Hits        77041   77074      +33     
+ Misses      14184   14180       -4     
+ Partials     2397    2394       -3
Impacted Files Coverage Δ
statsmodels/base/tests/test_penalties.py 100% <100%> (ø) ⬆️
statsmodels/base/_penalties.py 81.7% <100%> (+2.84%) ⬆️

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 c8cf0c9...fa6a592. Read the comment docs.

Comment thread statsmodels/base/_penalties.py Outdated
"""

def __init__(self, penalty, weights=None, restriction=None):
def __init__(self, penalty, weights=1., restriction=None):

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 really think it would be better to leave weights=None for the default and then below use

self.weights = weights if weights is not None else 1.

Same comment for other changes like this.

Then you can leave the doc string type for weight as ndarray, optional

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.

  1. it is a misleading practice to use None as a default but always change it to 1.0 If it always changed to 1.0 it should be 1.0 by default.
  2. as a user I couldn't understand the behavior of weights=None without looking into the code. It could be changed to 0.0,1.0,anystatisticsyouimagine under the hood and I now nothing about it without sources. Explicit is better than implicit.
  3. Leaving weights=None required for this code to work weights = weights if weights is not None else wts but this approach leads us to the point where user could just add weights argument and not remove wts and we will pick weights and not force user to actually replace a deprecated argument.
    @josef-pkt

@josef-pkt

Copy link
Copy Markdown
Member

What's the reason for these changes?

AFAICS, the old code is just as intended, i.e. it currently uses None as kind of sentinel value to check whether weights is used, i.e. defined by the user.

@bashtage

bashtage commented May 21, 2019 via email

Copy link
Copy Markdown
Member

@josef-pkt

Copy link
Copy Markdown
Member

The purpose of None here is mainly for the deprecation of wts, AFAIR.

I think weights=1. could be used after wts has been removed.

in general, the default for weights None or 1. is still unclear.

GLM uses None freq_weights=None, var_weights=None
The point is whether user defines weights. In some cases we can/could avoid extra computation if we know that weights is None.

The difference to WLS is that WLS is designed for weights, weights are an integral part of WLS.
In other models weights are extras, and None means we don't use weights, (even if the code uses weights=1. or weights=np.ones(nobs)

@bashtage

Copy link
Copy Markdown
Member

This looks pretty good now. Minimal change to get things working and tests.

@josef-pkt

Copy link
Copy Markdown
Member

looks very good to me, Thanks

aside: GAM does not have (verified) support for weights yet, and some of the weight usages are still unclear, but that most likely will not directly affect the penalty classes

@bashtage

Copy link
Copy Markdown
Member

Thanks for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: incorrect return value in penalties

5 participants