-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Fix scalar iloc rebase #17163
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 scalar iloc rebase #17163
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1085,3 +1085,24 @@ def cast_scalar_to_array(shape, value, dtype=None): | |
values.fill(fill_value) | ||
|
||
return values | ||
|
||
|
||
def _maybe_convert_indexer(indexer, until): | ||
""" | ||
Convert slice, tuple, list or scalar "indexer" to 1-d array of indices, | ||
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. I think it would be ok to first do a PR to add a level to our indexing structure of code, IOW
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. Just for completeness: recall that part of this (i.e. the 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. yeah I'd rather not introduce a 'temporary' fix. |
||
using "until" as maximum for upwards open slices. | ||
""" | ||
|
||
if is_scalar(indexer): | ||
return np.array([indexer], dtype=int) | ||
|
||
if isinstance(indexer, np.ndarray): | ||
if indexer.dtype == bool: | ||
return np.where(indexer)[0] | ||
return indexer | ||
|
||
if isinstance(indexer, slice): | ||
stop = until if indexer.stop is None else indexer.stop | ||
return np.arange(stop, dtype=int)[indexer] | ||
|
||
return np.array(indexer, dtype=int) |
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.
this is likely duplicating some code in pandas.core.indexing. Also doesn't belong here as its purely an indexing converter (so put it in pandas.core.indexing)
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 will use it also in
BlockManager
: can you confirm you suggestion is still valid?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.
that's fine. it just belongs in internal utlities related to indexing (and not internal casting type things). yes it is casting but is purely related to indexing (and not data types)