-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
SparseArray compatibility issues in e.g. sklearn. Series.shape and SparseArray.shape output not consistent. #21126
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
Comments
Seems like we inherit shape from @property
def shape(self):
return (len(self),) Interested in making a PR? |
@Xparx. Let me know if you're going to work on this. If not, I would be interested in picking this ticket up. |
@nprad. Feel free to pick this up. |
nprad
added a commit
to nprad/pandas
that referenced
this issue
May 25, 2018
nprad
added a commit
to nprad/pandas
that referenced
this issue
May 25, 2018
nprad
added a commit
to nprad/pandas
that referenced
this issue
May 25, 2018
nprad
added a commit
to nprad/pandas
that referenced
this issue
May 25, 2018
Merged
4 tasks
jorisvandenbossche
pushed a commit
to jorisvandenbossche/pandas
that referenced
this issue
Jun 8, 2018
…nd SparseArray (pandas-dev#21126) (pandas-dev#21198) (cherry picked from commit 5348e06)
david-liu-brattle-1
pushed a commit
to david-liu-brattle-1/pandas
that referenced
this issue
Jun 18, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code Sample
Problem description
Using packages that internally translate pandas dataframes to arrays (like sklearn) requires vectors and matrices to be specific sizes. Using sparse data matrices in pandas produces unpredictable results as internals of sklearn will translate pandas to SparseArray arrays and check sizes. The size of
spdf[1].values.shape
is not guaranteed to have the expected shape output.Also depending on the order of columns selection (after or before applying values) gives different results as the output of
spdf.values
is anumpy.ndarray
.Expected Output
I would expect the last statement in the code above to return True for all vectors in spdf.
I'm not sure this is a bug or intended feature but it struck me as weird as well as inconvenient when working with different libraries.
I encountered this running sklearn.linear_model.Lasso with a sparse target vector.
Output of
pd.show_versions()
pandas: 0.23.0
pytest: None
pip: 10.0.1
setuptools: 39.1.0
Cython: None
numpy: 1.14.2
scipy: 1.0.1
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: 0.5.0
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: 2.4.9
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: 4.1.1
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.1.15
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: