-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: sparse take #43654
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
PERF: sparse take #43654
Conversation
tm.assert_sp_array_equal(result, expected) | ||
|
||
result = sparse.take(np.array([1, 0, -1]), fill_value=True) | ||
expected = SparseArray([np.nan, np.nan, np.nan], kind="block") | ||
expected = SparseArray([np.nan, np.nan, np.nan], kind=kind) |
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.
In all other take
cases, we preserve the kind
of SparseIndex
, so I think it makes sense to do so here (otherwise is surprising value-dependent behavior IMO, somewhat expressed in the comment originally here).
|
||
return taken | ||
new_sp_index = make_sparse_index(len(indices), value_indices, kind=self.kind) | ||
return type(self)._simple_new(new_sp_values, new_sp_index, dtype=self.dtype) |
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.
Main reasoning for the simplifications here keeping same behavior is that take
with allow_fill=False
should give a result with the same dtype
as our SparseArray
lgtm. cc @jbrockmendel |
doc/source/whatsnew/v1.4.0.rst
Outdated
@@ -354,6 +354,7 @@ Performance improvements | |||
- Performance improvement in indexing with a :class:`MultiIndex` indexer on another :class:`MultiIndex` (:issue:43370`) | |||
- Performance improvement in :meth:`GroupBy.quantile` (:issue:`43469`) | |||
- :meth:`SparseArray.min` and :meth:`SparseArray.max` no longer require converting to a dense array (:issue:`43526`) | |||
- Performance improvement in :meth:`SparseArray.take` with ``allow_fill=False`` (:issue:`?`) |
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.
fill in ?
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.
Thanks!
thanks @mzeitlin11 |
This helps some on #41023 because
__getitem__
usestake
internally forSparseArray
. However, the big gain there can follow after this to move towards not densifying on__getitem__
with a sliceBenchmarks: