3
���h#] � @ sF U d Z ddlmZ ddlmZmZ ddlZddlmZm Z m
Z
mZmZm
Z
mZmZmZ ddlZddlmZ edd�Zed d
�Zi Ze
eef i Ze
eef i Ze
eef dgZee G dd
� d
ee�Zeeed�dd�ZdXeed�dd�Z dd�dd�Z!dYeed�dd�Z"dZeedd�dd�Z#ed�d d!�Z$G d"d#� d#�Z%G d$d%� d%�Z&d&Z'd'Z(d(Z)d)Z*e&e e'�a+e&e!e(�a,e&e#e*�a-e&e"e)�Z.e%e�Z/G d*d+� d+e�Z0d[ee1ee
e egef e
e egef dd,�d-d.�a2d\ee
e e
e dd/�d0d1�Z3eee d2�d3d4�Z4eee
eef ef d5�d6d7�Z5eed5�d8d9�Z6ed:�d;d<�Z7ed:�d=d>�Z8eed5�d?d@�Z9eed5�dAdB�Z:eedC�dDdE�Z;d]ee edG�dHdI�Z<edJdK� �Z=ee e egdf dL�dMdN�Z>e egdf d�dOdP�Z?e egdf d�dQdR�Z@e
eA ddS�dTdU�ZBe>eA�ZCe>e�ZDe>eE�ZFe>e�ZGe?eeHf�ZIed�dVdW�ZJdS )^a�
The config module holds package-wide configurables and provides
a uniform API for working with them.
Overview
========
This module supports the following requirements:
- options are referenced using keys in dot.notation, e.g. "x.y.option - z".
- keys are case-insensitive.
- functions should accept partial/regex keys, when unambiguous.
- options can be registered by modules at import time.
- options can be registered at init-time (via core.config_init)
- options have a default value, and (optionally) a description and
validation function associated with them.
- options can be deprecated, in which case referencing them
should produce a warning.
- deprecated options can optionally be rerouted to a replacement
so that accessing a deprecated option reroutes to a differently
named option.
- options can be reset to their default value.
- all option can be reset to their default value at once.
- all options in a certain sub - namespace can be reset at once.
- the user can set / get / reset or ask for the description of an option.
- a developer can register and mark an option as deprecated.
- you can register a callback to be invoked when the option value
is set or reset. Changing the stored value is considered misuse, but
is not verboten.
Implementation
==============
- Data is stored using nested dictionaries, and should be accessed
through the provided API.
- "Registered options" and "Deprecated options" have metadata associated
with them, which are stored in auxiliary dictionaries keyed on the
fully-qualified key, e.g. "x.y.z.option".
- the config_init module is imported by the package's __init__.py file.
placing any register_option() calls there will ensure those options
are available as soon as pandas is loaded. If you use register_option
in a module, it will only be available after that module is imported,
which you should be aware of.
- `config_prefix` is a context_manager (for use with the `with` keyword)
which can save developers some typing, see the docstring.
� )�
namedtuple)�ContextDecorator�contextmanagerN) �Any�Callable�Dict�Iterable�List�Optional�Tuple�Type�cast)�F�DeprecatedOptionzkey msg rkey removal_ver�RegisteredOptionzkey defval doc validator cb�allc @ s e Zd ZdZdS )�OptionErrorzU
Exception for pandas.options, backwards compatible with KeyError
checks
N)�__name__�
__module__�__qualname__�__doc__� r r �7/tmp/pip-build-5_djhm0z/pandas/pandas/_config/config.pyr K s r )�pat�silent�returnc C sf t | �}t|�dkr2|s t| � tdt| �� ���t|�dkrFtd��|d }|sZt|� t|�}|S )Nr zNo such keys(s): � zPattern matched multiple keys)�_select_options�len�_warn_if_deprecatedr �repr�_translate_key)r r �keys�keyr r r �_get_single_keyV s r$ F)r r c C s t | |�}t|�\}}|| S )N)r$ � _get_root)r r r# �root�kr r r �_get_optionh s
r( )r c
O s� t | �}| s|d dkr"td��|jdd�}|rRt|j� �d }td|� d���x�t| d d d� | dd d� �D ]z\}}t||�}t|�}|r�|j r�|j |� t
|�\} }|| |< |