Skip to content

Commit 72cee4a

Browse files
ShaharNavehWillAyd
authored andcommitted
DOC: Style format (#30119)
1 parent 5924c7f commit 72cee4a

File tree

2 files changed

+62
-30
lines changed

2 files changed

+62
-30
lines changed

pandas/core/accessor.py

+26-14
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def _dir_additions(self):
3535

3636
def __dir__(self):
3737
"""
38-
Provide method name lookup and completion
38+
Provide method name lookup and completion.
39+
40+
Notes
41+
-----
3942
Only provide 'public' methods.
4043
"""
4144
rv = set(dir(type(self)))
@@ -45,7 +48,7 @@ def __dir__(self):
4548

4649
class PandasDelegate:
4750
"""
48-
An abstract base class for delegating methods/properties.
51+
Abstract base class for delegating methods/properties.
4952
"""
5053

5154
def _delegate_property_get(self, name, *args, **kwargs):
@@ -66,12 +69,15 @@ def _add_delegate_accessors(
6669
6770
Parameters
6871
----------
69-
cls : the class to add the methods/properties to
70-
delegate : the class to get methods/properties & doc-strings
71-
accessors : string list of accessors to add
72-
typ : 'property' or 'method'
73-
overwrite : boolean, default False
74-
Overwrite the method/property in the target class if it exists.
72+
cls
73+
Class to add the methods/properties to.
74+
delegate
75+
Class to get methods/properties and doc-strings.
76+
accessors : list of str
77+
List of accessors to add.
78+
typ : {'property', 'method'}
79+
overwrite : bool, default False
80+
Overwrite the method/property in the target class if it exists.
7581
"""
7682

7783
def _create_delegator_property(name):
@@ -122,7 +128,7 @@ def delegate_names(delegate, accessors, typ: str, overwrite: bool = False):
122128
accessors : Sequence[str]
123129
List of accessor to add.
124130
typ : {'property', 'method'}
125-
overwrite : boolean, default False
131+
overwrite : bool, default False
126132
Overwrite the method/property in the target class if it exists.
127133
128134
Returns
@@ -152,16 +158,22 @@ def add_delegate_accessors(cls):
152158

153159
class CachedAccessor:
154160
"""
155-
Custom property-like object (descriptor) for caching accessors.
161+
Custom property-like object.
162+
163+
A descriptor for caching accessors.
156164
157165
Parameters
158166
----------
159167
name : str
160-
The namespace this will be accessed under, e.g. ``df.foo``.
168+
Namespace that will be accessed under, e.g. ``df.foo``.
161169
accessor : cls
162-
The class with the extension methods. The class' __init__ method
163-
should expect one of a ``Series``, ``DataFrame`` or ``Index`` as
164-
the single argument ``data``.
170+
Class with the extension methods.
171+
172+
Notes
173+
-----
174+
For accessor, The class's __init__ method assumes that one of
175+
``Series``, ``DataFrame`` or ``Index`` as the
176+
single argument ``data``.
165177
"""
166178

167179
def __init__(self, name: str, accessor) -> None:

pandas/core/sorting.py

+36-16
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,24 @@ def get_group_index(labels, shape, sort: bool, xnull: bool):
3131
3232
Parameters
3333
----------
34-
labels: sequence of arrays
34+
labels : sequence of arrays
3535
Integers identifying levels at each location
36-
shape: sequence of ints same length as labels
36+
shape : sequence of ints
3737
Number of unique levels at each location
38-
sort: boolean
38+
sort : bool
3939
If the ranks of returned ids should match lexical ranks of labels
40-
xnull: boolean
40+
xnull : bool
4141
If true nulls are excluded. i.e. -1 values in the labels are
42-
passed through
42+
passed through.
43+
4344
Returns
4445
-------
4546
An array of type int64 where two elements are equal if their corresponding
4647
labels are equal at all location.
48+
49+
Notes
50+
-----
51+
The length of `labels` and `shape` must be identical.
4752
"""
4853

4954
def _int64_cut_off(shape) -> int:
@@ -104,7 +109,6 @@ def maybe_lift(lab, size):
104109

105110
def get_compressed_ids(labels, sizes):
106111
"""
107-
108112
Group_index is offsets into cartesian product of all possible labels. This
109113
space can be huge, so this function compresses it, by computing offsets
110114
(comp_ids) into the list of unique labels (obs_group_ids).
@@ -117,7 +121,6 @@ def get_compressed_ids(labels, sizes):
117121
Returns
118122
-------
119123
tuple of (comp_ids, obs_group_ids)
120-
121124
"""
122125
ids = get_group_index(labels, sizes, sort=True, xnull=False)
123126
return compress_group_index(ids, sort=True)
@@ -153,14 +156,13 @@ def decons_group_index(comp_labels, shape):
153156

154157
def decons_obs_group_ids(comp_ids, obs_ids, shape, labels, xnull: bool):
155158
"""
156-
reconstruct labels from observed group ids
159+
Reconstruct labels from observed group ids.
157160
158161
Parameters
159162
----------
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.
162165
"""
163-
164166
if not xnull:
165167
lift = np.fromiter(((a == -1).any() for a in labels), dtype="i8")
166168
shape = np.asarray(shape, dtype="i8") + lift
@@ -188,6 +190,11 @@ def indexer_from_factorized(labels, shape, compress: bool = True):
188190

189191

190192
def lexsort_indexer(keys, orders=None, na_position: str = "last"):
193+
"""
194+
Parameters
195+
----------
196+
na_position : {'first', 'last'}, default 'last'
197+
"""
191198
from pandas.core.arrays import Categorical
192199

193200
labels = []
@@ -237,9 +244,17 @@ def nargsort(
237244
items, kind: str = "quicksort", ascending: bool = True, na_position: str = "last"
238245
):
239246
"""
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'
243258
"""
244259
items = extract_array(items)
245260
mask = np.asarray(isna(items))
@@ -272,7 +287,7 @@ def nargsort(
272287

273288
class _KeyMapper:
274289
"""
275-
Ease my suffering. Map compressed group id -> key tuple
290+
Map compressed group id -> key tuple.
276291
"""
277292

278293
def __init__(self, comp_ids, ngroups: int, levels, labels):
@@ -303,7 +318,12 @@ def get_flattened_iterator(comp_ids, ngroups, levels, labels):
303318

304319

305320
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+
"""
307327
shape = [len(x) for x in keys]
308328

309329
group_index = get_group_index(label_list, shape, sort=True, xnull=True)

0 commit comments

Comments
 (0)