-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: Documentation for pandas.core.indexes.api #22980
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
Merged
datapythonista
merged 12 commits into
pandas-dev:master
from
lowerthansound:indexapi-document
Nov 4, 2018
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b895c3c
Comment _all_indexes_same
548a428
Comment _get_consensus_names
4360846
Comment _sanitize_and_check
ec20c27
Comment _union_indexes
974fdc3
Comment _get_combined_index
76c3e5d
Comment _get_objs_combined_axis
efb5dc0
Comment _unique_indices
2e30318
Add Parameters and Returns to docstrings
5fb5dd4
Start content on next line
e624495
Add space after parameter names
10cb2dd
Add missing periods in docstrings
62e7a3e
Fix parameter types
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,16 +44,51 @@ | |
|
||
|
||
def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True): | ||
# Extract combined index: return intersection or union (depending on the | ||
# value of "intersect") of indexes on given axis, or None if all objects | ||
# lack indexes (e.g. they are numpy arrays) | ||
"""Extract combined index: return intersection or union (depending on the | ||
value of "intersect") of indexes on given axis, or None if all objects | ||
lack indexes (e.g. they are numpy arrays) | ||
|
||
Parameters | ||
---------- | ||
objs: list of objects | ||
Each object will only be considered if it has a _get_axis | ||
attribute | ||
intersect: boolean, default False | ||
If True, calculate the intersection between indexes. Otherwise, | ||
calculate the union | ||
axis: {0 or 'index', 1 or 'outer'}, default 0 | ||
The axis to extract indexes from | ||
sort: boolean, default True | ||
Whether the result index should come out sorted or not | ||
|
||
Returns | ||
------- | ||
Index | ||
""" | ||
obs_idxes = [obj._get_axis(axis) for obj in objs | ||
if hasattr(obj, '_get_axis')] | ||
if obs_idxes: | ||
return _get_combined_index(obs_idxes, intersect=intersect, sort=sort) | ||
|
||
|
||
def _get_combined_index(indexes, intersect=False, sort=False): | ||
"""Return the union or intersection of indexes | ||
|
||
Parameters | ||
---------- | ||
indexes: a list of Index or list objects | ||
When intersect=True, do not accept list of lists | ||
intersect: boolean, default False | ||
If True, calculate the intersection between indexes. Otherwise, | ||
calculate the union | ||
sort: boolean, default False | ||
Whether the result index should come out sorted or not | ||
|
||
Returns | ||
------- | ||
Index | ||
""" | ||
|
||
# TODO: handle index names! | ||
indexes = com.get_distinct_objs(indexes) | ||
if len(indexes) == 0: | ||
|
@@ -77,6 +112,20 @@ def _get_combined_index(indexes, intersect=False, sort=False): | |
|
||
|
||
def _union_indexes(indexes, sort=True): | ||
"""Return the union of indexes | ||
|
||
The behavior of sort and names is not consistent. | ||
|
||
Parameters | ||
---------- | ||
indexes: a list of Index or list objects | ||
sort: boolean, default True | ||
Whether the result index should come out sorted or not | ||
|
||
Returns | ||
------- | ||
Index | ||
""" | ||
if len(indexes) == 0: | ||
raise AssertionError('Must have at least 1 Index to union') | ||
if len(indexes) == 1: | ||
|
@@ -88,6 +137,18 @@ def _union_indexes(indexes, sort=True): | |
indexes, kind = _sanitize_and_check(indexes) | ||
|
||
def _unique_indices(inds): | ||
"""Convert indexes to lists and concatenate them, removing duplicates | ||
|
||
The final dtype is inferred. | ||
|
||
Parameters | ||
---------- | ||
inds: a list of Index or list objects | ||
|
||
Returns | ||
------- | ||
Index | ||
""" | ||
def conv(i): | ||
if isinstance(i, Index): | ||
i = i.tolist() | ||
|
@@ -126,6 +187,25 @@ def conv(i): | |
|
||
|
||
def _sanitize_and_check(indexes): | ||
"""Verify the type of indexes and convert lists to Index | ||
|
||
Cases: | ||
|
||
- [list, list, ...]: Return ([list, list, ...], 'list') | ||
- [list, Index, ...]: Return _sanitize_and_check([Index, Index, ...]) | ||
Lists are sorted and converted to 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. Will add period to this too |
||
- [Index, Index, ...]: Return ([Index, Index, ...], TYPE) | ||
TYPE = 'special' if at least one special type, 'array' otherwise | ||
|
||
Parameters | ||
---------- | ||
indexes: a list of Index or list objects | ||
|
||
Returns | ||
------- | ||
sanitized_indexes: list of Index or list objects | ||
type: {'list', 'array', 'special'} | ||
""" | ||
kinds = list({type(index) for index in indexes}) | ||
|
||
if list in kinds: | ||
|
@@ -144,6 +224,20 @@ def _sanitize_and_check(indexes): | |
|
||
|
||
def _get_consensus_names(indexes): | ||
"""Give a consensus 'names' to indexes | ||
|
||
If there's exactly one non-empty 'names', return this, | ||
otherwise, return empty. | ||
|
||
Parameters | ||
---------- | ||
indexes: a list of index objects | ||
|
||
Returns | ||
------- | ||
list | ||
A list representing the consensus 'names' found | ||
""" | ||
|
||
# find the non-none names, need to tupleify to make | ||
# the set hashable, then reverse on return | ||
|
@@ -155,6 +249,17 @@ def _get_consensus_names(indexes): | |
|
||
|
||
def _all_indexes_same(indexes): | ||
"""Determine if all indexes contain the same elements | ||
|
||
Parameters | ||
---------- | ||
indexes: a list of Index objects | ||
|
||
Returns | ||
------- | ||
boolean | ||
True if all indexes contain the same elements, False otherwise | ||
""" | ||
first = indexes[0] | ||
for index in indexes[1:]: | ||
if not first.equals(index): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.