-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
ENH/PERF SparseArray.take indexing #12796
Conversation
@@ -307,13 +316,14 @@ def _get_val_at(self, loc): | |||
else: | |||
return _index.get_value_at(self, sp_loc) | |||
|
|||
def take(self, indices, axis=0): |
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 use the shared_docs here?
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.
Done.
ind_val = indexer[i] | ||
if ind_val < 0 or self.length <= ind_val: | ||
results[i] = -1 | ||
else: |
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.
I think you need to filter first, then call:
inds.searchsorted(indices_to_find)
IOW it takes an array as an input (and outputs and array).
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.
@jreback thanks, changed to vectorized version.
95de480
to
33829a0
Compare
@jreback rebased, and now green. |
if allow_fill and fill_value is not None: | ||
# allow -1 to indicate self.fill_value, | ||
# self.fill_value may not be NaN | ||
if (indices < -1).any(): |
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.
so if you can make an issue at some point we can move this stuff (and combin with the guts of assert_fillable_take
as an internal function in core/algorighthms.py
, but ok for now.
thanks @sinhrks |
SparseDataFrame
indexing test is not sufficient)git diff upstream/master | flake8 --diff
Added more tests for sparse indexing. Fixed followings:
SparseArray.take
has optimized logic to omit densenp.ndarray
creation.SparseSeires.iloc
can work with negative indices. MadeSparseArray.take
to handle negative indices as the same rule asIndex
(API: Index.take inconsistently handle fill_value #12676)