Skip to content

SparseDataFrame constructor raises AttributeError with SparseArray #28407

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
simonjayhawkins opened this issue Sep 12, 2019 · 2 comments · Fixed by #28425
Closed

SparseDataFrame constructor raises AttributeError with SparseArray #28407

simonjayhawkins opened this issue Sep 12, 2019 · 2 comments · Fixed by #28425
Labels
Sparse Sparse Data Type
Milestone

Comments

@simonjayhawkins
Copy link
Member

mypy error: pandas\core\sparse\frame.py:94:25: error: Item "SparseArray" of "Union[SparseSeries, SparseArray]" has no attribute "index"

Code Sample, a copy-pastable example if possible

>>> import pandas as pd
>>> pd.__version__
'0.25.0+332.g261c3a667'
>>> sa = pd.SparseArray([1,2,3])
>>> sa
[1, 2, 3]
Fill: 0
IntIndex
Indices: array([0, 1, 2])

>>> pd.DataFrame(sa)
   0
0  1
1  2
2  3
>>> pd.SparseDataFrame(sa)
__main__:1: FutureWarning: SparseDataFrame is deprecated and will be removed in a future version.
Use a regular DataFrame whose columns are SparseArrays instead.

See http://pandas.pydata.org/pandas-docs/stable/user_guide/sparse.html#migrating for more.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\simon\OneDrive\code\pandas-simonjayhawkins\pandas\core\sparse\frame.py", line 94, in __init__
    index = data.index
AttributeError: 'SparseArray' object has no attribute 'index'
>>>

Problem description

The docstring for SparseDataFrame states that the types accepted for the data argument of the constructor are the same types as can be passed to DataFrame.

the DataFrame constructor accepts a SparseArray, the SparseDataFrame constructor raises AttributeError: 'SparseArray' object has no attribute 'index'

@simonjayhawkins simonjayhawkins added the Sparse Sparse Data Type label Sep 12, 2019
@TomAugspurger
Copy link
Contributor

Probably not worth fixing, giving that the sparse subclasses are being removed.

@simonjayhawkins
Copy link
Member Author

Probably not worth fixing, giving that the sparse subclasses are being removed.

I agree. issue posted for visibility and cross-reference for mypy error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sparse Sparse Data Type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants