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

BUG: SparseDataFrame from scipy.sparse.dia.dia_matrix returns incorrect dataframe #16177

Closed
keitakurita opened this issue Apr 30, 2017 · 4 comments

Comments

@keitakurita
Copy link
Contributor

keitakurita commented Apr 30, 2017

Code Sample, a copy-pastable example if possible

>>> import numpy as np
>>> import scipy.sparse
>>> A = np.arange(1, 5).reshape(2, 2)
>>> A
array([[1, 2],
       [3, 4]])
>>> spm = scipy.sparse.bsr.bsr_matrix(A)
>>> pd.SparseDataFrame(spm)
   0  1
0  1  2
1  3  4
>>> spm = scipy.sparse.dia.dia_matrix(A)
>>> pd.SparseDataFrame(spm)
   0  1
0  3  4
1  1  2
>>> pd.SparseDataFrame(A)
   0  1
0  1  2
1  3  4

Problem description

Initialization of SparseDataFrame with scipy.sparse.dia.dia_matrix returns a different result from direct initialization from np.ndarray and other sparse matrix formats. This is unexpected behavior since the user would expect the output DataFrame to be consistent with the initial array.

Expected Output

>>> pd.SparseDataFrame(spm)
   0  1
0  1  2
1  3  4

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: 075eca1 python: 3.6.1.final.0 python-bits: 64 OS: Darwin OS-release: 16.5.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: ja_JP.UTF-8 LOCALE: ja_JP.UTF-8

pandas: 0.20.0rc1+29.g075eca1
pytest: 3.0.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.18.1
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
pandas_gbq: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented May 1, 2017

cc @kernc

@jreback
Copy link
Contributor

jreback commented May 1, 2017

this is a dupe of #16179 it appears.

@jreback jreback closed this as completed May 1, 2017
@keitakurita
Copy link
Contributor Author

keitakurita commented May 1, 2017

@jreback
If this issue is going to be closed, I think it would be a good idea to add the error for the dok format sparse matrix to issue #16179 , since these are two distinct sparse matrix formats with slightly different buggy behaviors.

@jreback
Copy link
Contributor

jreback commented May 1, 2017

you can update the other issue if you like, this is just another case

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

No branches or pull requests

2 participants