Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG/REF: assignment to slices in numpy >= 1.9 (emplike) #1754

Closed
josef-pkt opened this issue Jun 10, 2014 · 1 comment

Comments

Projects
None yet
1 participant
@josef-pkt
Copy link
Member

commented Jun 10, 2014

It's not a bug in the sense of producing wrong numbers.
Numpy is changing the behavior for assigment to slices (index or mask based)

Christoph Gohlke tested the numpy 1.9b1 against several packages
http://www.lfd.uci.edu/~gohlke/pythonlibs/tests/20140609-win-amd64-py2.7-numpy-1.9.0b1/statsmodels_test.txt

3 errors, this one is typical

======================================================================
ERROR: statsmodels.emplike.tests.test_origin.TestOrigin.test_ci_beta
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27-x64\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "X:\Python27-x64\lib\site-packages\statsmodels\emplike\tests\test_origin.py", line 35, in test_ci_beta
    ci = self.res1.conf_int_el(1)
  File "X:\Python27-x64\lib\site-packages\statsmodels\emplike\originregress.py", line 256, in conf_int_el
    lowerl = optimize.brentq(f, lower_bound, self.params[param_num])
  File "X:\Python27-x64\lib\site-packages\scipy\optimize\zeros.py", line 415, in brentq
    r = _zeros._brentq(f,a,b,xtol,rtol,maxiter,args,full_output,disp)
  File "X:\Python27-x64\lib\site-packages\statsmodels\emplike\originregress.py", line 255, in <lambda>
    stochastic_exog=stochastic_exog)[0] - r0
  File "X:\Python27-x64\lib\site-packages\statsmodels\emplike\originregress.py", line 202, in el_test
    return_weights=return_weights)
  File "X:\Python27-x64\lib\site-packages\statsmodels\regression\linear_model.py", line 1519, in el_test
    stochastic_exog=stochastic_exog)
  File "X:\Python27-x64\lib\site-packages\statsmodels\emplike\elregress.py", line 58, in _opt_nuis_regress
    params[nuis_param_index] = nuisance_params
ValueError: shape mismatch: value array of shape (2,) could not be broadcast to indexing result of shape (0,)

(quoting parts of my post to numpy mailing list)

params[nuis_param_index] = nuisance_params
ValueError: shape mismatch: value array of shape (2,) could not be
broadcast to indexing result of shape (0,)

As far as I have figured out based on Christoph's test failures

nuis_param_index is array([], dtype=int32)
and because numpy didn't assign anything, nuisance_params was picked
essentially arbitrary along this code path

>>> x = np.arange(5.)
>>> we_dont_care_what_this_is = np.random.randn(10)
>>> x[[]] = we_dont_care_what_this_is
>>> x
array([ 0.,  1.,  2.,  3.,  4.])

It looks like fix is simply to use [] for the nuisance_params in this case (there are none) in linear_model.OLSResults.el_test

        if len(param_nums) == len(params):
            llr = opt_fun_inst._opt_nuis_regress([]

all emplike/tests pass on my computer

@josef-pkt

This comment has been minimized.

Copy link
Member Author

commented Jun 10, 2014

we don't have a specific comp-emplike label for git issues

@josef-pkt josef-pkt closed this in 9526d51 Jun 18, 2014

josef-pkt added a commit that referenced this issue Jun 18, 2014

Merge pull request #1771 from josef-pkt/REF_indexing_empty_1754
REF numpy >1.9 compatibility, indexing into empty slice closes #1754

PierreBdR pushed a commit to PierreBdR/statsmodels that referenced this issue Sep 2, 2014

PierreBdR pushed a commit to PierreBdR/statsmodels that referenced this issue Sep 2, 2014

Merge pull request statsmodels#1771 from josef-pkt/REF_indexing_empty…
…_1754

REF numpy >1.9 compatibility, indexing into empty slice closes statsmodels#1754
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.