4444
4545
4646def _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+
51+ Parameters
52+ ----------
53+ objs: list of objects
54+ Each object will only be considered if it has a _get_axis
55+ attribute
56+ intersect: boolean, default False
57+ If True, calculate the intersection between indexes. Otherwise,
58+ calculate the union
59+ axis: {0 or 'index', 1 or 'outer'}, default 0
60+ The axis to extract indexes from
61+ sort: boolean, default True
62+ Whether the result index should come out sorted or not
63+
64+ Returns
65+ -------
66+ Index
67+ """
5068 obs_idxes = [obj ._get_axis (axis ) for obj in objs
5169 if hasattr (obj , '_get_axis' )]
5270 if obs_idxes :
5371 return _get_combined_index (obs_idxes , intersect = intersect , sort = sort )
5472
5573
5674def _get_combined_index (indexes , intersect = False , sort = False ):
75+ """Return the union or intersection of indexes
76+
77+ Parameters
78+ ----------
79+ indexes: a list of Index or array-like objects
80+ intersect: boolean, default False
81+ If True, calculate the intersection between indexes. Otherwise,
82+ calculate the union
83+ sort: boolean, default False
84+ Whether the result index should come out sorted or not
85+
86+ Returns
87+ -------
88+ Index
89+ """
90+
5791 # TODO: handle index names!
5892 indexes = com .get_distinct_objs (indexes )
5993 if len (indexes ) == 0 :
@@ -77,6 +111,20 @@ def _get_combined_index(indexes, intersect=False, sort=False):
77111
78112
79113def _union_indexes (indexes , sort = True ):
114+ """Return the union of indexes
115+
116+ The behavior of sort and names is not consistent.
117+
118+ Parameters
119+ ----------
120+ indexes: a list of Index or array-like objects
121+ sort: boolean, default True
122+ Whether the result index should come out sorted or not
123+
124+ Returns
125+ -------
126+ Index
127+ """
80128 if len (indexes ) == 0 :
81129 raise AssertionError ('Must have at least 1 Index to union' )
82130 if len (indexes ) == 1 :
@@ -88,6 +136,18 @@ def _union_indexes(indexes, sort=True):
88136 indexes , kind = _sanitize_and_check (indexes )
89137
90138 def _unique_indices (inds ):
139+ """Convert indexes to lists and concatenate them, removing duplicates
140+
141+ The final dtype is inferred.
142+
143+ Parameters
144+ ----------
145+ inds: a list of Index or array-like objects
146+
147+ Returns
148+ -------
149+ Index
150+ """
91151 def conv (i ):
92152 if isinstance (i , Index ):
93153 i = i .tolist ()
@@ -126,6 +186,25 @@ def conv(i):
126186
127187
128188def _sanitize_and_check (indexes ):
189+ """Verify the type of indexes and convert lists to Index
190+
191+ Cases:
192+
193+ - [list, list, ...]: Return ([list, list, ...], 'list')
194+ - [list, Index, ...]: Return _sanitize_and_check([Index, Index, ...])
195+ Lists are sorted and converted to Index
196+ - [Index, Index, ...]: Return ([Index, Index, ...], TYPE)
197+ TYPE = 'special' if at least one special type, 'array' otherwise
198+
199+ Parameters
200+ ----------
201+ indexes: a list of Index or array-like objects
202+
203+ Returns
204+ -------
205+ sanitized_indexes: list of Index or array-like objects
206+ type: {'list', 'array', 'special'}
207+ """
129208 kinds = list ({type (index ) for index in indexes })
130209
131210 if list in kinds :
@@ -144,6 +223,20 @@ def _sanitize_and_check(indexes):
144223
145224
146225def _get_consensus_names (indexes ):
226+ """Give a consensus 'names' to indexes
227+
228+ If there's exactly one non-empty 'names', return this,
229+ otherwise, return empty.
230+
231+ Parameters
232+ ----------
233+ indexes: a list of index objects
234+
235+ Returns
236+ -------
237+ list
238+ A list representing the consensus 'names' found
239+ """
147240
148241 # find the non-none names, need to tupleify to make
149242 # the set hashable, then reverse on return
@@ -155,6 +248,17 @@ def _get_consensus_names(indexes):
155248
156249
157250def _all_indexes_same (indexes ):
251+ """Determine if all indexes contain the same elements
252+
253+ Parameters
254+ ----------
255+ indexes: a list of Index objects
256+
257+ Returns
258+ -------
259+ boolean
260+ True if all indexes contain the same elements, False otherwise
261+ """
158262 first = indexes [0 ]
159263 for index in indexes [1 :]:
160264 if not first .equals (index ):
0 commit comments