@@ -31,19 +31,24 @@ def get_group_index(labels, shape, sort: bool, xnull: bool):
31
31
32
32
Parameters
33
33
----------
34
- labels: sequence of arrays
34
+ labels : sequence of arrays
35
35
Integers identifying levels at each location
36
- shape: sequence of ints same length as labels
36
+ shape : sequence of ints
37
37
Number of unique levels at each location
38
- sort: boolean
38
+ sort : bool
39
39
If the ranks of returned ids should match lexical ranks of labels
40
- xnull: boolean
40
+ xnull : bool
41
41
If true nulls are excluded. i.e. -1 values in the labels are
42
- passed through
42
+ passed through.
43
+
43
44
Returns
44
45
-------
45
46
An array of type int64 where two elements are equal if their corresponding
46
47
labels are equal at all location.
48
+
49
+ Notes
50
+ -----
51
+ The length of `labels` and `shape` must be identical.
47
52
"""
48
53
49
54
def _int64_cut_off (shape ) -> int :
@@ -104,7 +109,6 @@ def maybe_lift(lab, size):
104
109
105
110
def get_compressed_ids (labels , sizes ):
106
111
"""
107
-
108
112
Group_index is offsets into cartesian product of all possible labels. This
109
113
space can be huge, so this function compresses it, by computing offsets
110
114
(comp_ids) into the list of unique labels (obs_group_ids).
@@ -117,7 +121,6 @@ def get_compressed_ids(labels, sizes):
117
121
Returns
118
122
-------
119
123
tuple of (comp_ids, obs_group_ids)
120
-
121
124
"""
122
125
ids = get_group_index (labels , sizes , sort = True , xnull = False )
123
126
return compress_group_index (ids , sort = True )
@@ -153,14 +156,13 @@ def decons_group_index(comp_labels, shape):
153
156
154
157
def decons_obs_group_ids (comp_ids , obs_ids , shape , labels , xnull : bool ):
155
158
"""
156
- reconstruct labels from observed group ids
159
+ Reconstruct labels from observed group ids.
157
160
158
161
Parameters
159
162
----------
160
- xnull: boolean,
161
- if nulls are excluded; i.e. -1 labels are passed through
163
+ xnull : bool
164
+ If nulls are excluded; i.e. -1 labels are passed through.
162
165
"""
163
-
164
166
if not xnull :
165
167
lift = np .fromiter (((a == - 1 ).any () for a in labels ), dtype = "i8" )
166
168
shape = np .asarray (shape , dtype = "i8" ) + lift
@@ -188,6 +190,11 @@ def indexer_from_factorized(labels, shape, compress: bool = True):
188
190
189
191
190
192
def lexsort_indexer (keys , orders = None , na_position : str = "last" ):
193
+ """
194
+ Parameters
195
+ ----------
196
+ na_position : {'first', 'last'}, default 'last'
197
+ """
191
198
from pandas .core .arrays import Categorical
192
199
193
200
labels = []
@@ -237,9 +244,17 @@ def nargsort(
237
244
items , kind : str = "quicksort" , ascending : bool = True , na_position : str = "last"
238
245
):
239
246
"""
240
- This is intended to be a drop-in replacement for np.argsort which
241
- handles NaNs. It adds ascending and na_position parameters.
242
- GH #6399, #5231
247
+ Intended to be a drop-in replacement for np.argsort which handles NaNs.
248
+
249
+ Adds ascending and na_position parameters.
250
+
251
+ (GH #6399, #5231)
252
+
253
+ Parameters
254
+ ----------
255
+ kind : str, default 'quicksort'
256
+ ascending : bool, default True
257
+ na_position : {'first', 'last'}, default 'last'
243
258
"""
244
259
items = extract_array (items )
245
260
mask = np .asarray (isna (items ))
@@ -272,7 +287,7 @@ def nargsort(
272
287
273
288
class _KeyMapper :
274
289
"""
275
- Ease my suffering. Map compressed group id -> key tuple
290
+ Map compressed group id -> key tuple.
276
291
"""
277
292
278
293
def __init__ (self , comp_ids , ngroups : int , levels , labels ):
@@ -303,7 +318,12 @@ def get_flattened_iterator(comp_ids, ngroups, levels, labels):
303
318
304
319
305
320
def get_indexer_dict (label_list , keys ):
306
- """ return a dict of {labels} -> {indexers} """
321
+ """
322
+ Returns
323
+ -------
324
+ dict
325
+ Labels mapped to indexers.
326
+ """
307
327
shape = [len (x ) for x in keys ]
308
328
309
329
group_index = get_group_index (label_list , shape , sort = True , xnull = True )
0 commit comments