@@ -203,22 +203,19 @@ def set_option(*args) -> None:
203
203
Parameters
204
204
----------
205
205
*args : str | object | dict
206
- Options can be provided in one of two forms:
207
-
208
- 1. As pairs of arguments, where each pair is interpreted as (pattern, value):
209
- - pattern: str
210
- Regexp which should match a single option.
211
- - value: object
212
- New value of option.
213
-
214
- 2. As a single dictionary, where each key is a pattern and the corresponding
215
- value is the new option value.
206
+ Arguments provided in pairs, which will be interpreted as (pattern, value)
207
+ pairs and in a single dictionary, where each key is a pattern and the
208
+ corresponding value is the new option value.
209
+ pattern: str
210
+ Regexp which should match a single option
211
+ value: object
212
+ New value of option
216
213
217
214
.. warning::
218
215
219
216
Partial pattern matches are supported for convenience, but unless you
220
- use the full option name (e.g. `` x.y.z.option_name`` ), your code may break
221
- in future versions if new options with similar names are introduced.
217
+ use the full option name (e.g. x.y.z.option_name), your code may break in
218
+ future versions if new options with similar names are introduced.
222
219
223
220
Returns
224
221
-------
@@ -227,19 +224,17 @@ def set_option(*args) -> None:
227
224
228
225
Raises
229
226
------
230
- ValueError
231
- If an odd number of non-keyword arguments is provided.
232
- TypeError
233
- If keyword arguments are provided.
234
- OptionError
235
- If no such option exists.
227
+ ValueError if odd numbers of non-keyword arguments are provided
228
+ TypeError if keyword arguments are provided
229
+ OptionError if no such option exists
236
230
237
231
See Also
238
232
--------
239
233
get_option : Retrieve the value of the specified option.
240
234
reset_option : Reset one or more options to their default value.
241
235
describe_option : Print the description for one or more registered options.
242
- option_context : Context manager to temporarily set options in a `with` statement.
236
+ option_context : Context manager to temporarily set options in a ``with``
237
+ statement.
243
238
244
239
Notes
245
240
-----
@@ -248,32 +243,28 @@ def set_option(*args) -> None:
248
243
249
244
Examples
250
245
--------
251
- Setting options using pairs:
252
-
253
246
>>> pd.set_option("display.max_columns", 4)
247
+ >>> # another way of passing options
248
+ >>> # pd.set_option({"display.max_columns": 4, "display.width": 80})
254
249
>>> df = pd.DataFrame([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
255
250
>>> df
256
- 0 1 ... 3 4
257
- 0 1 2 ... 4 5
258
- 1 6 7 ... 9 10
251
+ 0 1 ... 3 4
252
+ 0 1 2 ... 4 5
253
+ 1 6 7 ... 9 10
259
254
[2 rows x 5 columns]
260
255
>>> pd.reset_option("display.max_columns")
261
-
262
- Setting options using a dictionary:
263
-
264
- >>> pd.set_option({"display.max_columns": 4, "display.width": 80})
265
256
"""
266
257
nargs = len (args )
267
- pairs = []
258
+ pairs : list [ tuple [ Any , Any ]] = []
268
259
269
260
if nargs == 1 and isinstance (args [0 ], dict ):
270
- pairs = args [0 ].items ()
261
+ pairs = list ( args [0 ].items () )
271
262
else :
272
263
if not nargs or nargs % 2 != 0 :
273
264
raise ValueError (
274
265
"Must provide an even number of non-keyword arguments or a dictionary"
275
266
)
276
- pairs = zip (args [::2 ], args [1 ::2 ])
267
+ pairs = list ( zip (args [::2 ], args [1 ::2 ]) )
277
268
278
269
for k , v in pairs :
279
270
key = _get_single_key (k )
@@ -285,7 +276,6 @@ def set_option(*args) -> None:
285
276
if opt .cb :
286
277
opt .cb (key )
287
278
288
-
289
279
### Second Approach Supports both *args[pd.set_option(options)]
290
280
### and **kwargs[pd.set_option(**options)] where options=dict
291
281
0 commit comments