Repository: statsmodels/statsmodels

Issue:
BUG: incorrect return value in penalties
https://github.com/josef-pkt/statsmodels/commit/17df3615f70dedb33e504f8c18508b14bd63d296#r29280998

returns wts instead of weights

related to name changes #4642
BUG: incorrect return value in penalties
https://github.com/josef-pkt/statsmodels/commit/17df3615f70dedb33e504f8c18508b14bd63d296#r29280998

returns wts instead of weights

related to name changes #4642


Discussion:
temporarily prio-high.

Fix is changing one word, but we need to check the unit tests, i.e. `weights` either has insufficient unit tests or those are too loose.
(My unit tests might not use much that code path.)
this is still wrong in master, AFAICS
temporarily prio-high.

Fix is changing one word, but we need to check the unit tests, i.e. `weights` either has insufficient unit tests or those are too loose.
(My unit tests might not use much that code path.)
this is still wrong in master, AFAICS

Resolving patch:
diff --git a/statsmodels/base/_penalties.py b/statsmodels/base/_penalties.py
--- a/statsmodels/base/_penalties.py
+++ b/statsmodels/base/_penalties.py
@@ -32,7 +32,7 @@ def _check_wts(weights, wts):
         warnings.warn('`wts` method is deprecated. Use `weights` instead',
                       DeprecationWarning)
     weights = weights if weights is not None else wts
-    return wts
+    return weights
 
 
 class Penalty(object):


Test patch:
diff --git a/statsmodels/base/tests/test_penalties.py b/statsmodels/base/tests/test_penalties.py
--- a/statsmodels/base/tests/test_penalties.py
+++ b/statsmodels/base/tests/test_penalties.py
@@ -7,12 +7,14 @@
 """
 
 import numpy as np
-from numpy.testing import assert_allclose
+from numpy.testing import assert_allclose, assert_equal
 
 import statsmodels.base._penalties as smpen
 from statsmodels.tools.numdiff import approx_fprime, approx_hess
 
 
+
+
 class CheckPenalty(object):
 
     def test_symmetry(self):
@@ -100,6 +102,22 @@ def setup_class(cls):
         cls.params = np.column_stack((x0, x0))
         cls.pen = smpen.PseudoHuber(0.1)
 
+    def test_backward_compatibility(self):
+        wts = [0.5]
+        pen = smpen.PseudoHuber(0.1, wts=wts)
+        assert_equal(pen.weights, wts)
+
+    def test_deprecated_priority(self):
+        weights = [1.0]
+        wts = [0.5]
+        pen = smpen.PseudoHuber(0.1, weights=weights, wts=wts)
+        assert_equal(pen.weights, weights)
+
+    def test_weights_assignment(self):
+        weights = [1.0, 2.0]
+        pen = smpen.PseudoHuber(0.1, weights=weights)
+        assert_equal(pen.weights, weights)
+
 
 class TestL2(CheckPenalty):
 
@@ -109,6 +127,22 @@ def setup_class(cls):
         cls.params = np.column_stack((x0, x0))
         cls.pen = smpen.L2()
 
+    def test_backward_compatibility(self):
+        wts = [0.5]
+        pen = smpen.L2(wts=wts)
+        assert_equal(pen.weights, wts)
+
+    def test_deprecated_priority(self):
+        weights = [1.0]
+        wts = [0.5]
+        pen = smpen.L2(weights=weights, wts=wts)
+        assert_equal(pen.weights, weights)
+
+    def test_weights_assignment(self):
+        weights = [1.0, 2.0]
+        pen = smpen.L2(weights=weights)
+        assert_equal(pen.weights, weights)
+
 
 class TestNonePenalty(CheckPenalty):