Skip to content

ERR: give better error message when providing wrong sparse matrix type in from_coo #26554

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

Closed
jorisvandenbossche opened this issue May 29, 2019 · 1 comment · Fixed by #26584
Closed
Labels
Error Reporting Incorrect or improved errors from pandas good first issue Sparse Sparse Data Type
Milestone

Comments

@jorisvandenbossche
Copy link
Member

pd.Series.sparse.from_coo only accepts a coo matrix format, but when giving it different matrix type, you get a not so useful error message:

In [11]: import scipy.sparse

In [12]: m = scipy.sparse.csr_matrix(np.array([[0,1],[0,0]]))

In [13]: pd.Series.sparse.from_coo(m)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-b31c13c3a79c> in <module>
----> 1 pd.Series.sparse.from_coo(m)

~/scipy/pandas/pandas/core/arrays/sparse.py in from_coo(cls, A, dense_index)
   2015         from pandas import Series
   2016 
-> 2017         result = _coo_to_sparse_series(A, dense_index=dense_index,
   2018                                        sparse_series=False)
   2019         result = Series(result.array, index=result.index, copy=False)

~/scipy/pandas/pandas/core/sparse/scipy_sparse.py in _coo_to_sparse_series(A, dense_index)
    122     Convert a scipy.sparse.coo_matrix to a SparseSeries.
    123 
--> 124     Parameters
    125     ----------
    126     A : scipy.sparse.coo.coo_matrix

~/miniconda3/envs/dev37/lib/python3.7/site-packages/scipy/sparse/base.py in __getattr__(self, attr)
    687             return self.getnnz()
    688         else:
--> 689             raise AttributeError(attr + " not found")
    690 
    691     def transpose(self, axes=None, copy=False):

AttributeError: row not found
@jorisvandenbossche jorisvandenbossche added Error Reporting Incorrect or improved errors from pandas Sparse Sparse Data Type good first issue labels May 29, 2019
@jorisvandenbossche jorisvandenbossche added this to the Contributions Welcome milestone May 29, 2019
@fhoang7
Copy link
Contributor

fhoang7 commented May 31, 2019

Happy to take a look at this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas good first issue Sparse Sparse Data Type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants