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

[FIX] Table: Fix ensure_copy for sparse matrices #1456

Merged
merged 1 commit into from
Jul 15, 2016

Conversation

nikicc
Copy link
Contributor

@nikicc nikicc commented Jul 14, 2016

ensure_copy is checking whether an array is a view through the .base argument which doesn't exist on scipy.sparse matrices. Since scipy.sparse don't work with views (e.g. indexing returns a copy of the matrix) the check should only be performed for dense matrices.

@codecov-io
Copy link

codecov-io commented Jul 14, 2016

Current coverage is 87.94%

Merging #1456 into master will increase coverage by 0.01%

@@             master      #1456   diff @@
==========================================
  Files            77         77          
  Lines          7582       7584     +2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           6667       6670     +3   
+ Misses          915        914     -1   
  Partials          0          0          

Sunburst

Powered by Codecov. Last updated by 1ba45c1...75bbe05

"""
if self.X.base is not None:
if not sp.issparse(self.X) and self.X.base is not None:
self.X = self.X.copy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if they are sparse, no copy is made?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently not, this is left to the constructor. As far as I understand ensure_copy only ensures that the data is not a view and makes a copy if it is. Since sparse matrices do not have views (at least I think so) I propose to skip the check. Currently the copy is made in the constructor anyway and hence we probably do not need to make an other here.

@astaric
Copy link
Member

astaric commented Jul 14, 2016

Could you also add a test for copy with sparse data?

@nikicc
Copy link
Contributor Author

nikicc commented Jul 14, 2016

A simple test was added 😄

`ensure_copy` is checking whether an array is a view through the `.base` argument which doesn't exist on `scipy.sparse` matrices. Since `scipy.sparse` don't work with views (e.g. indexing returns a copy of the matrix) the check should only be performed for dense matrices.
@astaric astaric merged commit 6e8eab1 into biolab:master Jul 15, 2016
@nikicc nikicc deleted the fix-ensure-copy branch July 15, 2016 08:40
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

Successfully merging this pull request may close these issues.

4 participants