Skip to content

SparseDataFrame with dense Series or unknown type #19374

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
datapythonista opened this issue Jan 24, 2018 · 0 comments · Fixed by #19377
Closed

SparseDataFrame with dense Series or unknown type #19374

datapythonista opened this issue Jan 24, 2018 · 0 comments · Fixed by #19377
Labels
Bug Sparse Sparse Data Type
Milestone

Comments

@datapythonista
Copy link
Member

Code Sample, a copy-pastable example if possible

import pandas

pandas.SparseDataFrame(pandas.Series())

Problem description

I've seen there are plans to SparseDataFrame. But reporting anyway.

The above code, creating a SparseDataFrame with a dense Series fails with a not very descriptive error:

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
<ipython-input-6-b9708ff05a7c> in <module>()
      1 import pandas
      2 
----> 3 pandas.SparseDataFrame(pandas.Series())

~/anaconda3/lib/python3.6/site-packages/pandas/core/sparse/frame.py in __init__(self, data, index, columns, default_kind, default_fill_value, dtype, copy)
    120                 mgr = mgr.astype(dtype)
    121 
--> 122         generic.NDFrame.__init__(self, mgr)
    123 
    124     @property

UnboundLocalError: local variable 'mgr' referenced before assignment

Any other type provided to the constructor fails with the same error.

Expected Output

I'd expect an empty series (if the dense Series has a name, or columns is provided).

Or a useful error message, if the data type is not accepted.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.13-300.fc27.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.utf8
LOCALE: en_GB.UTF-8

pandas: 0.23.0.dev0+152.g2952fbd55.dirty
pytest: 3.3.0
pip: 9.0.1
setuptools: 36.5.0.post20170921
Cython: 0.27.3
numpy: 1.13.3
scipy: 1.0.0
pyarrow: 0.7.1
xarray: None
IPython: 6.2.1
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.1
openpyxl: 2.4.9
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@gfyoung gfyoung added Bug Sparse Sparse Data Type labels Jan 24, 2018
@jreback jreback added this to the 0.23.0 milestone Jan 25, 2018
jreback pushed a commit that referenced this issue Jan 27, 2018
…r, and providing useful error messages for other types (#19374) (#19377)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Sparse Sparse Data Type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants