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

SparseDataFrame with dense Series or unknown type #19374

Closed
datapythonista opened this Issue Jan 24, 2018 · 0 comments

Comments

Projects
None yet
3 participants
@datapythonista
Member

datapythonista commented Jan 24, 2018

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

datapythonista pushed a commit to datapythonista/pandas that referenced this issue Jan 24, 2018

Marc Garcia
BUG adding support for dense Series in the SparseDataFrame constructo…
…r, and providing useful error messages for other types (pandas-dev#19374)

datapythonista pushed a commit to datapythonista/pandas that referenced this issue Jan 24, 2018

Marc Garcia
BUG adding support for dense Series in the SparseDataFrame constructo…
…r, and providing useful error messages for other types (pandas-dev#19374)

@jreback jreback added this to the 0.23.0 milestone Jan 25, 2018

datapythonista pushed a commit to datapythonista/pandas that referenced this issue Jan 25, 2018

Marc Garcia
BUG adding support for dense Series in the SparseDataFrame constructo…
…r, and providing useful error messages for other types (pandas-dev#19374)

datapythonista pushed a commit to datapythonista/pandas that referenced this issue Jan 25, 2018

Marc Garcia
BUG adding support for dense Series in the SparseDataFrame constructo…
…r, and providing useful error messages for other types (pandas-dev#19374)

datapythonista pushed a commit to datapythonista/pandas that referenced this issue Jan 26, 2018

Marc Garcia
BUG adding support for dense Series in the SparseDataFrame constructo…
…r, and providing useful error messages for other types (pandas-dev#19374)

jreback added a commit that referenced this issue Jan 27, 2018

BUG adding support for dense Series in the SparseDataFrame constructo…
…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