MCPcopy
hub / github.com/pandas-dev/pandas / register_option

Function register_option

pandas/_config/config.py:521–593  ·  view source on GitHub ↗

Register an option in the package-wide pandas config object Parameters ---------- key : str Fully-qualified key, e.g. "x.y.option - z". defval : object Default value of the option. doc : str Description of the option. validator : Callable, option

(
    key: str,
    defval: object,
    doc: str = "",
    validator: Callable[[object], Any] | None = None,
    cb: Callable[[str], Any] | None = None,
)

Source from the content-addressed store, hash-verified

519
520
521def register_option(
522 key: str,
523 defval: object,
524 doc: str = "",
525 validator: Callable[[object], Any] | None = None,
526 cb: Callable[[str], Any] | None = None,
527) -> None:
528 """
529 Register an option in the package-wide pandas config object
530
531 Parameters
532 ----------
533 key : str
534 Fully-qualified key, e.g. "x.y.option - z".
535 defval : object
536 Default value of the option.
537 doc : str
538 Description of the option.
539 validator : Callable, optional
540 Function of a single argument, should raise `ValueError` if
541 called with a value which is not a legal value for the option.
542 cb
543 a function of a single argument "key", which is called
544 immediately after an option value is set/reset. key is
545 the full name of the option.
546
547 Raises
548 ------
549 ValueError if `validator` is specified and `defval` is not a valid value.
550
551 """
552 import keyword
553 import tokenize
554
555 key = key.lower()
556
557 if key in _registered_options:
558 raise OptionError(f"Option '{key}' has already been registered")
559 if key in _reserved_keys:
560 raise OptionError(f"Option '{key}' is a reserved key")
561
562 # the default value should be legal
563 if validator:
564 validator(defval)
565
566 # walk the nested dict, creating dicts as needed along the path
567 path = key.split(".")
568
569 for k in path:
570 if not re.match("^" + tokenize.Name + "$", k):
571 raise ValueError(f"{k} is not a valid identifier")
572 if keyword.iskeyword(k):
573 raise ValueError(f"{k} is a python keyword")
574
575 cursor = _global_config
576 msg = "Path prefix to option '{option}' is already an option"
577
578 for i, p in enumerate(path[:-1]):

Callers

nothing calls this directly

Calls 7

OptionErrorClass · 0.85
RegisteredOptionClass · 0.85
lowerMethod · 0.80
splitMethod · 0.80
matchMethod · 0.80
formatMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected