KeyError when calling to_coo() on SparseDataFrame · Issue #18414 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

In [45]: t_df = idx = pd.Int64Index([2,3,4]) ...: t_df = pd.DataFrame(data=0, columns=idx, index=idx) ...: t_df.apply(pd.SparseArray).sparse.to_coo() # This line blows up in find_common_types

Problem description

Currently, a KeyError is raised while trying to get the first column type (cast.py#1070).

Expected Output

A (very) sparse matrix

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.3.final.0 python-bits: 64 OS: Linux OS-release: 4.10.0-38-generic machine: x86_64 processor: byteorder: little LC_ALL: None LANG: C.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.21.0
pytest: None
pip: 10.0.0.subpip_fix
setuptools: 36.5.0
Cython: None
numpy: 1.13.3
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: 4.1.0
bs4: 4.6.0
html5lib: 1.0b10
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: 0.5.0