Skip to content

Commit cb77f89

Browse files
Merge pull request #7236 from jorisvandenbossche/doc-fixes2
DOC: clean-up docstrings of option functions
2 parents e165ddd + f93448e commit cb77f89

File tree

3 files changed

+82
-41
lines changed

3 files changed

+82
-41
lines changed

doc/source/api.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ Serialization / IO / Conversion
489489
Series.to_frame
490490
Series.to_hdf
491491
Series.to_sql
492-
Series.to_gbq
493492
Series.to_msgpack
494493
Series.to_json
495494
Series.to_sparse
@@ -1200,6 +1199,9 @@ Indexing, iteration
12001199

12011200
.. currentmodule:: pandas
12021201

1202+
.. autosummary::
1203+
:toctree: generated/
1204+
12031205
Grouper
12041206

12051207
.. currentmodule:: pandas.core.groupby
@@ -1226,8 +1228,11 @@ Computations / Descriptive Stats
12261228

12271229
.. currentmodule:: pandas
12281230

1231+
General utility functions
1232+
-------------------------
1233+
12291234
Working with options
1230-
--------------------
1235+
~~~~~~~~~~~~~~~~~~~~
12311236

12321237
.. autosummary::
12331238
:toctree: generated/
@@ -1238,6 +1243,7 @@ Working with options
12381243
set_option
12391244
option_context
12401245

1246+
12411247
..
12421248
HACK - see github issue #4539. To ensure old links remain valid, include
12431249
here the autosummaries with previous currentmodules as a comment and add

pandas/core/config.py

+74-35
Original file line numberDiff line numberDiff line change
@@ -224,45 +224,55 @@ def __doc__(self):
224224
opts_list=opts_list)
225225

226226
_get_option_tmpl = """
227-
get_option(pat) - Retrieves the value of the specified option
227+
get_option(pat)
228+
229+
Retrieves the value of the specified option.
228230
229231
Available options:
232+
230233
{opts_list}
231234
232235
Parameters
233236
----------
234-
pat - str/regexp which should match a single option.
235-
236-
Note: partial matches are supported for convenience, but unless you use the
237-
full option name (e.g. x.y.z.option_name), your code may break in future
238-
versions if new options with similar names are introduced.
237+
pat : str
238+
Regexp which should match a single option.
239+
Note: partial matches are supported for convenience, but unless you use the
240+
full option name (e.g. x.y.z.option_name), your code may break in future
241+
versions if new options with similar names are introduced.
239242
240243
Returns
241244
-------
242-
result - the value of the option
245+
result : the value of the option
243246
244247
Raises
245248
------
246-
OptionError if no such option exists
249+
OptionError : if no such option exists
250+
251+
Notes
252+
-----
253+
The available options with its descriptions:
247254
248255
{opts_desc}
249256
"""
250257

251258
_set_option_tmpl = """
252-
set_option(pat,value) - Sets the value of the specified option
259+
set_option(pat, value)
260+
261+
Sets the value of the specified option.
253262
254263
Available options:
264+
255265
{opts_list}
256266
257267
Parameters
258268
----------
259-
pat - str/regexp which should match a single option.
260-
261-
Note: partial matches are supported for convenience, but unless you use the
262-
full option name (e.g. x.y.z.option_name), your code may break in future
263-
versions if new options with similar names are introduced.
264-
265-
value - new value of option.
269+
pat : str
270+
Regexp which should match a single option.
271+
Note: partial matches are supported for convenience, but unless you use the
272+
full option name (e.g. x.y.z.option_name), your code may break in future
273+
versions if new options with similar names are introduced.
274+
value :
275+
new value of option.
266276
267277
Returns
268278
-------
@@ -272,55 +282,72 @@ def __doc__(self):
272282
------
273283
OptionError if no such option exists
274284
285+
Notes
286+
-----
287+
The available options with its descriptions:
288+
275289
{opts_desc}
276290
"""
277291

278292
_describe_option_tmpl = """
279-
describe_option(pat,_print_desc=False) Prints the description
280-
for one or more registered options.
293+
describe_option(pat, _print_desc=False)
294+
295+
Prints the description for one or more registered options.
281296
282297
Call with not arguments to get a listing for all registered options.
283298
284299
Available options:
300+
285301
{opts_list}
286302
287303
Parameters
288304
----------
289-
pat - str, a regexp pattern. All matching keys will have their
290-
description displayed.
291-
292-
_print_desc - if True (default) the description(s) will be printed
293-
to stdout otherwise, the description(s) will be returned
294-
as a unicode string (for testing).
305+
pat : str
306+
Regexp pattern. All matching keys will have their description displayed.
307+
_print_desc : bool, default True
308+
If True (default) the description(s) will be printed to stdout.
309+
Otherwise, the description(s) will be returned as a unicode string
310+
(for testing).
295311
296312
Returns
297313
-------
298314
None by default, the description(s) as a unicode string if _print_desc
299315
is False
300316
317+
Notes
318+
-----
319+
The available options with its descriptions:
320+
301321
{opts_desc}
302322
"""
303323

304324
_reset_option_tmpl = """
305-
reset_option(pat) - Reset one or more options to their default value.
325+
reset_option(pat)
326+
327+
Reset one or more options to their default value.
306328
307329
Pass "all" as argument to reset all options.
308330
309331
Available options:
332+
310333
{opts_list}
311334
312335
Parameters
313336
----------
314-
pat - str/regex if specified only options matching `prefix`* will be reset
315-
316-
Note: partial matches are supported for convenience, but unless you use the
317-
full option name (e.g. x.y.z.option_name), your code may break in future
318-
versions if new options with similar names are introduced.
337+
pat : str/regex
338+
If specified only options matching `prefix*` will be reset.
339+
Note: partial matches are supported for convenience, but unless you
340+
use the full option name (e.g. x.y.z.option_name), your code may break
341+
in future versions if new options with similar names are introduced.
319342
320343
Returns
321344
-------
322345
None
323346
347+
Notes
348+
-----
349+
The available options with its descriptions:
350+
324351
{opts_desc}
325352
"""
326353

@@ -337,6 +364,18 @@ def __doc__(self):
337364

338365

339366
class option_context(object):
367+
"""
368+
Context manager to temporarily set options in the `with` statement context.
369+
370+
You need to invoke as ``option_context(pat, val, [(pat, val), ...])``.
371+
372+
Examples
373+
--------
374+
375+
>>> with option_context('display.max_rows', 10, 'display.max_columns', 5):
376+
...
377+
378+
"""
340379

341380
def __init__(self, *args):
342381
if not (len(args) % 2 == 0 and len(args) >= 2):
@@ -589,13 +628,13 @@ def _build_option_description(k):
589628
o = _get_registered_option(k)
590629
d = _get_deprecated_option(k)
591630

592-
s = u('%s: ') % k
631+
s = u('%s : ') % k
593632
if o:
594633
s += u('[default: %s] [currently: %s]') % (o.defval,
595634
_get_option(k, True))
596635

597636
if o.doc:
598-
s += '\n' + '\n '.join(o.doc.strip().split('\n'))
637+
s += '\n '.join(o.doc.strip().split('\n'))
599638
else:
600639
s += 'No description available.\n'
601640

@@ -604,7 +643,7 @@ def _build_option_description(k):
604643
s += (u(', use `%s` instead.') % d.rkey if d.rkey else '')
605644
s += u(')\n')
606645

607-
s += '\n'
646+
s += '\n\n'
608647
return s
609648

610649

@@ -615,9 +654,9 @@ def pp_options_list(keys, width=80, _print=False):
615654
from itertools import groupby
616655

617656
def pp(name, ks):
618-
pfx = (name + '.[' if name else '')
657+
pfx = ('- ' + name + '.[' if name else '')
619658
ls = wrap(', '.join(ks), width, initial_indent=pfx,
620-
subsequent_indent=' ' * len(pfx), break_long_words=False)
659+
subsequent_indent=' ', break_long_words=False)
621660
if ls and ls[-1] and name:
622661
ls[-1] = ls[-1] + ']'
623662
return ls

pandas/core/config_init.py

-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
a string with the desired format of the number. This is used
9898
in some places like SeriesFormatter.
9999
See core.format.EngFormatter for an example.
100-
101100
"""
102101

103102
max_colwidth_doc = """
@@ -162,7 +161,6 @@
162161

163162
pc_max_seq_items = """
164163
: int or None
165-
166164
when pretty-printing a long sequence, no more then `max_seq_items`
167165
will be printed. If items are omitted, they will be denoted by the
168166
addition of "..." to the resulting string.
@@ -179,15 +177,13 @@
179177

180178
pc_large_repr_doc = """
181179
: 'truncate'/'info'
182-
183180
For DataFrames exceeding max_rows/max_cols, the repr (and HTML repr) can
184181
show a truncated table (the default from 0.13), or switch to the view from
185182
df.info() (the behaviour in earlier versions of pandas).
186183
"""
187184

188185
pc_mpl_style_doc = """
189186
: bool
190-
191187
Setting this to 'default' will modify the rcParams used by matplotlib
192188
to give plots a more pleasing visual style by default.
193189
Setting this to None/False restores the values to their initial value.

0 commit comments

Comments
 (0)