Skip to content
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

KeyError when calling to_coo() on SparseDataFrame #18414

Closed
ediphy-azorab opened this issue Nov 21, 2017 · 5 comments · Fixed by #38567
Closed

KeyError when calling to_coo() on SparseDataFrame #18414

ediphy-azorab opened this issue Nov 21, 2017 · 5 comments · Fixed by #38567
Assignees
Labels
Milestone

Comments

@ediphy-azorab
Copy link

ediphy-azorab commented Nov 21, 2017

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

@mukherjees
Copy link

Same issue exists with Pandas 0.22.0 and Python 3.6.4.

@h4ste
Copy link

h4ste commented Jul 23, 2018

Exists with Pandas 0.23.3 and Python 3.6.6

INSTALLED VERSIONS

commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-128-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.3
pytest: None
pip: 10.0.1
setuptools: 39.1.0
Cython: None
numpy: 1.14.5
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.4.0
sphinx: None
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jorisvandenbossche
Copy link
Member

We should be using positional indexing here (so types.iloc[0] instead of types[0])

@jorisvandenbossche jorisvandenbossche modified the milestones: 0.25.0, Contributions Welcome May 29, 2019
@TomAugspurger
Copy link
Contributor

Still applies to DataFrame[sparse]. Updated the original post.

@khalludi
Copy link

khalludi commented Feb 7, 2020

take

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

Successfully merging a pull request may close this issue.

8 participants