Skip to content
This repository was archived by the owner on Dec 22, 2019. It is now read-only.

Commit a925706

Browse files
author
araraonline
committed
Comment functions in pandas.core.indexes.api
1 parent f4fae35 commit a925706

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

pandas/core/indexes/api.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@
4444

4545

4646
def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True):
47-
# Extract combined index: return intersection or union (depending on the
48-
# value of "intersect") of indexes on given axis, or None if all objects
49-
# lack indexes (e.g. they are numpy arrays)
47+
"""Extract combined index: return intersection or union (depending on the
48+
value of "intersect") of indexes on given axis, or None if all objects
49+
lack indexes (e.g. they are numpy arrays)
50+
"""
5051
obs_idxes = [obj._get_axis(axis) for obj in objs
5152
if hasattr(obj, '_get_axis')]
5253
if obs_idxes:
5354
return _get_combined_index(obs_idxes, intersect=intersect, sort=sort)
5455

5556

5657
def _get_combined_index(indexes, intersect=False, sort=False):
58+
"""Return the union or intersection of indexes
59+
"""
60+
5761
# TODO: handle index names!
5862
indexes = com.get_distinct_objs(indexes)
5963
if len(indexes) == 0:
@@ -77,6 +81,10 @@ def _get_combined_index(indexes, intersect=False, sort=False):
7781

7882

7983
def _union_indexes(indexes, sort=True):
84+
"""Return the union of indexes
85+
86+
The behavior of sort and names is not consistent.
87+
"""
8088
if len(indexes) == 0:
8189
raise AssertionError('Must have at least 1 Index to union')
8290
if len(indexes) == 1:
@@ -88,6 +96,10 @@ def _union_indexes(indexes, sort=True):
8896
indexes, kind = _sanitize_and_check(indexes)
8997

9098
def _unique_indices(inds):
99+
"""Convert indexes to lists and concatenate them, removing duplicates
100+
101+
The final dtype is inferred.
102+
"""
91103
def conv(i):
92104
if isinstance(i, Index):
93105
i = i.tolist()
@@ -126,6 +138,16 @@ def conv(i):
126138

127139

128140
def _sanitize_and_check(indexes):
141+
"""Verify the type of indexes and convert lists to Index
142+
143+
Cases:
144+
145+
- [list, list, ...]: Return ([list, list, ...], 'list')
146+
- [list, Index, ...]: Return _sanitize_and_check([Index, Index, ...])
147+
Lists are sorted and converted to Index
148+
- [Index, Index, ...]: Return ([Index, Index, ...], TYPE)
149+
TYPE = 'special' if at least one special type, 'array' otherwise
150+
"""
129151
kinds = list({type(index) for index in indexes})
130152

131153
if list in kinds:
@@ -144,6 +166,11 @@ def _sanitize_and_check(indexes):
144166

145167

146168
def _get_consensus_names(indexes):
169+
"""Give a consensus 'names' to indexes
170+
171+
If there's exactly one non-empty 'names', return this,
172+
otherwise, return empty.
173+
"""
147174

148175
# find the non-none names, need to tupleify to make
149176
# the set hashable, then reverse on return
@@ -155,6 +182,8 @@ def _get_consensus_names(indexes):
155182

156183

157184
def _all_indexes_same(indexes):
185+
"""Determine if all indexes contain the same elements
186+
"""
158187
first = indexes[0]
159188
for index in indexes[1:]:
160189
if not first.equals(index):

0 commit comments

Comments
 (0)