-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
PERF: optimize DataFrame.sparse.from_spmatrix performance #32825
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
Changes from 1 commit
3ffe7f2
93bf825
e21701b
e095e7f
11afe40
eda0732
40f4cd6
508fda5
0053817
42792a3
c8f7abc
e541b0d
0a0bafc
ce6619e
e063c8a
8efe3ad
20c3685
d750eb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
10000 There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,13 +240,13 @@ def from_spmatrix(cls, data, index=None, columns=None): | |
data.sort_indices() | ||
indices = data.indices | ||
indptr = data.indptr | ||
data = data.data | ||
dtype = SparseDtype(data.dtype, 0) | ||
array_data = data.data | ||
dtype = SparseDtype(array_data.dtype, 0) | ||
arrays = [] | ||
for i in range(n_columns): | ||
sl = slice(indptr[i], indptr[i + 1]) | ||
idx = IntIndex(n_rows, indices[sl], check_integrity=False) | ||
arr = SparseArray._simple_new(data[sl], idx, dtype) | ||
arr = SparseArray._simple_new(array_data[sl], idx, dtype) | ||
arrays.append(arr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, also tried with a generator here to avoid pre-allocating all the arrays, but it doesn't really matter. Most of the remaining run time is in |
||
return DataFrame._from_arrays(arrays, columns=columns, index=index) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line will be able to use the |
||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be already done in
tocsc
, but that's a scipy implementation detail, and it doesn't really cost much. We need to make sure indices are sorted, since we createIntIndex
withcheck_integrity=False
that used to check for this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment about that inline?