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: sparse: fixing unbound local error #5216

Merged
merged 1 commit into from Sep 4, 2015

Conversation

Projects
None yet
3 participants
@perimosocordiae
Copy link
Member

perimosocordiae commented Sep 1, 2015

M and N aren't defined in this conditional branch, so the following happens (on current master):

In [1]: import scipy.sparse as ss

In [2]: ss.coo_matrix(None, (4,5))
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-2-62651dfca412> in <module>()
----> 1 ss.coo_matrix(None, (4,5))

/usr/local/lib/python2.7/dist-packages/scipy/sparse/coo.pyc in __init__(self, arg1, shape, dtype, copy)
    163             warn('coo_matrix(None, shape=(M,N)) is deprecated, '
    164                     'use coo_matrix( (M,N) ) instead', DeprecationWarning)
--> 165             idx_dtype = get_index_dtype(maxval=max(M, N))
    166             self.shape = shape
    167             self.data = np.array([], getdtype(dtype, default=float))

UnboundLocalError: local variable 'M' referenced before assignment

The deprecation warning indicates that this kind of constructor call isn't recommended, so another alternative would be to remove the special handling altogether. For now, this PR fixes the bug.

BUG: sparse: fixing unbound local error
M and N aren't defined in this branch
@larsmans

This comment has been minimized.

Copy link
Contributor

larsmans commented Sep 4, 2015

This has been deprecated since at least 2007, but it was only broken in 62ec92f of January 2014. I'll merge the patch but submit a new PR removing the code path.

larsmans added a commit that referenced this pull request Sep 4, 2015

Merge pull request #5216 from perimosocordiae/patch-4
BUG: sparse: fixing unbound local error

@larsmans larsmans merged commit 3e4bff0 into scipy:master Sep 4, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@perimosocordiae perimosocordiae deleted the perimosocordiae:patch-4 branch Sep 8, 2015

@ewmoore ewmoore added this to the 0.17.0 milestone Sep 15, 2015

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.