HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/_config/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/_config/__pycache__/config.cpython-36.pyc
3

���h#]�	@sFUdZddlmZddlmZmZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZddlZddlmZedd�Zed	d
�ZiZe
eefiZe
eefiZe
eefdgZeeGdd
�d
ee�Zeeed�dd�ZdXeed�dd�Z dd�dd�Z!dYeed�dd�Z"dZeedd�dd�Z#ed�d d!�Z$Gd"d#�d#�Z%Gd$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/Gd*d+�d+e�Z0d[ee1ee
e	egefe
e	egefdd,�d-d.�a2d\ee
ee
edd/�d0d1�Z3eeed2�d3d4�Z4eee
eefefd5�d6d7�Z5eed5�d8d9�Z6ed:�d;d<�Z7ed:�d=d>�Z8eed5�d?d@�Z9eed5�dAdB�Z:eedC�dDdE�Z;d]eeedG�dHdI�Z<edJdK��Z=eee	egdfdL�dMdN�Z>e	egdfd�dOdP�Z?e	egdfd�dQdR�Z@e
eAddS�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@seZdZdZdS)�OptionErrorzU
    Exception for pandas.options, backwards compatible with KeyError
    checks
    N)�__name__�
__module__�__qualname__�__doc__�rr�7/tmp/pip-build-5_djhm0z/pandas/pandas/_config/config.pyrKsr)�pat�silent�returncCsft|�}t|�dkr2|s t|�tdt|�����t|�dkrFtd��|d}|sZt|�t|�}|S)NrzNo such keys(s): �zPattern matched multiple keys)�_select_options�len�_warn_if_deprecatedr�repr�_translate_key)rr�keys�keyrrr�_get_single_keyVsr$F)rrcCst||�}t|�\}}||S)N)r$�	_get_root)rrr#�root�krrr�_get_optionhs
r()rc

Os�t|�}|s|ddkr"td��|jdd�}|rRt|j��d}td|�d���x�t|ddd�|ddd��D]z\}}t||�}t|�}|r�|j	r�|j	|�t
|�\}	}||	|<|jrr|r�tj
d	d
��|j|�WdQRXqr|j|�qrWdS)N�rz4Must provide an even number of non-keyword argumentsrFz2_set_option() got an unexpected keyword argument "�"rT)�record)r�
ValueError�pop�listr"�	TypeError�zipr$�_get_registered_option�	validatorr%�cb�warnings�catch_warnings)
�args�kwargs�nargsrZkwargr'�vr#�or&rrr�_set_optionps&(


r;�T)r�_print_desccCsFt|�}t|�dkrtd��djdd�|D��}|r>t|�n|SdS)NrzNo such keys(s)�
cSsg|]}t|��qSr)�_build_option_description)�.0r'rrr�
<listcomp>�sz$_describe_option.<locals>.<listcomp>)rrr�join�print)rr=r"�srrr�_describe_option�s
rEcCsjt|�}t|�dkrtd��t|�dkrDt|�dkrD|dkrDtd��x |D]}t|t|j|d�qJWdS)NrzNo such keys(s)r�rz�You must specify at least 4 characters when resetting multiple keys, use the special keyword "all" to reset all the options to their default value)r)rrrr,r;�_registered_options�defval)rrr"r'rrr�
_reset_option�s 
rI)rcCst|dd�}t|�jS)NT)r)r$r1rH)rr#rrr�get_default_val�srJc@s\eZdZdZdeeefed�dd�Zeedd�dd	�Zed
�dd�Z	e
ed
�dd�ZdS)�DictWrapperz0 provide attribute-style access to a nested dictr<)�d�prefixcCs tj|d|�tj|d|�dS)NrLrM)�object�__setattr__)�selfrLrMrrr�__init__�szDictWrapper.__init__N)r#�valrcCsTtj|d�}|r|d7}||7}||jkrHt|j|t�rHt||�ntd��dS)NrM�.z.You can only set the value of existing options)rN�__getattribute__rL�
isinstance�dictr;r)rPr#rRrMrrrrO�szDictWrapper.__setattr__)r#cCs�tj|d�}|r|d7}||7}ytj|d�|}Wn,tk
r`}ztd�|�WYdd}~XnXt|t�rvt||�St|�SdS)NrMrSrLzNo such option)rNrT�KeyErrorrrUrVrKr()rPr#rMr9�errrrr�__getattr__�s

zDictWrapper.__getattr__)rcCst|jj��S)N)r.rLr")rPrrr�__dir__�szDictWrapper.__dir__)r<)rrrrr�strrrQrOrYrrZrrrrrK�s
rKc@s(eZdZdd�Zdd�Zedd��ZdS)�CallableDynamicDoccCs||_||_dS)N)�__doc_tmpl__�__func__)rP�funcZdoc_tmplrrrrQ�szCallableDynamicDoc.__init__cOs|j||�S)N)r^)rPr6�kwdsrrr�__call__�szCallableDynamicDoc.__call__cCs,tddd�}tttj���}|jj||d�S)NrF)r=)�	opts_desc�	opts_list)rE�pp_options_listr.rGr"r]�format)rPrbrcrrrr�szCallableDynamicDoc.__doc__N)rrrrQra�propertyrrrrrr\�sr\a;
get_option(pat)

Retrieves the value of the specified option.

Available options:

{opts_list}

Parameters
----------
pat : str
    Regexp which should match a single option.
    Note: partial matches are supported for convenience, but unless you use the
    full option name (e.g. x.y.z.option_name), your code may break in future
    versions if new options with similar names are introduced.

Returns
-------
result : the value of the option

Raises
------
OptionError : if no such option exists

Notes
-----
The available options with its descriptions:

{opts_desc}
aG
set_option(pat, value)

Sets the value of the specified option.

Available options:

{opts_list}

Parameters
----------
pat : str
    Regexp which should match a single option.
    Note: partial matches are supported for convenience, but unless you use the
    full option name (e.g. x.y.z.option_name), your code may break in future
    versions if new options with similar names are introduced.
value : object
    New value of option.

Returns
-------
None

Raises
------
OptionError if no such option exists

Notes
-----
The available options with its descriptions:

{opts_desc}
a�
describe_option(pat, _print_desc=False)

Prints the description for one or more registered options.

Call with not arguments to get a listing for all registered options.

Available options:

{opts_list}

Parameters
----------
pat : str
    Regexp pattern. All matching keys will have their description displayed.
_print_desc : bool, default True
    If True (default) the description(s) will be printed to stdout.
    Otherwise, the description(s) will be returned as a unicode string
    (for testing).

Returns
-------
None by default, the description(s) as a unicode string if _print_desc
is False

Notes
-----
The available options with its descriptions:

{opts_desc}
a5
reset_option(pat)

Reset one or more options to their default value.

Pass "all" as argument to reset all options.

Available options:

{opts_list}

Parameters
----------
pat : str/regex
    If specified only options matching `prefix*` will be reset.
    Note: partial matches are supported for convenience, but unless you
    use the full option name (e.g. x.y.z.option_name), your code may break
    in future versions if new options with similar names are introduced.

Returns
-------
None

Notes
-----
The available options with its descriptions:

{opts_desc}
c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�option_contexta
    Context manager to temporarily set options in the `with` statement context.

    You need to invoke as ``option_context(pat, val, [(pat, val), ...])``.

    Examples
    --------
    >>> with option_context('display.max_rows', 10, 'display.max_columns', 5):
    ...     ...
    cGsLt|�ddkot|�dks$td��tt|ddd�|ddd���|_dS)Nr)rz>Need to invoke as option_context(pat, val, [(pat, val), ...]).r)rr,r.r0�ops)rPr6rrrrQ�szoption_context.__init__cCs8dd�|jD�|_x |jD]\}}t||dd�qWdS)NcSs g|]\}}|t|dd�f�qS)T)r)r()r@rrRrrrrA�sz,option_context.__enter__.<locals>.<listcomp>T)r)rh�undor;)rPrrRrrr�	__enter__�szoption_context.__enter__cGs,|jr(x |jD]\}}t||dd�qWdS)NT)r)rir;)rPr6rrRrrr�__exit__�szoption_context.__exit__N)rrrrrQrjrkrrrrrg~s
rg)r#rH�docr2r3rc
Cs`ddl}ddl}|j�}|tkr0td|�d���|tkrHtd|�d���|rT||�|jd�}xH|D]@}tjd|j	d|�s�t
|�d	���|j|�rdt
|�d
���qdWt}	d}
x^t
|dd��D]J\}}t|	t�s�t|
jdj|d|��d
���||	k�ri|	|<|	|}	q�Wt|	t��s:t|
jdj|dd��d
���||	|d<t|||||d�t|<dS)a�
    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, optional
        Function of a single argument, should raise `ValueError` if
        called with a value which is not a legal value for the option.
    cb
        a function of a single argument "key", which is called
        immediately after an option value is set/reset. key is
        the full name of the option.

    Raises
    ------
    ValueError if `validator` is specified and `defval` is not a valid value.

    rNzOption 'z' has already been registeredz' is a reserved keyrS�^�$z is not a valid identifierz is a python keywordz5Path prefix to option '{option}' is already an optionr)�option)r#rHrlr2r3���rprp)�keyword�tokenize�lowerrGr�_reserved_keys�split�re�match�Namer,�	iskeyword�_global_config�	enumeraterUrVrerBr)
r#rHrlr2r3rqrr�pathr'�cursor�msg�i�prrr�register_option�s8




r�)r#r~�rkeyrcCs6|j�}|tkr td|�d���t||||�t|<dS)a
    Mark option `key` as deprecated, if code attempts to access this option,
    a warning will be produced, using `msg` if given, or a default message
    if not.
    if `rkey` is given, any access to the key will be re-routed to `rkey`.

    Neither the existence of `key` nor that if `rkey` is checked. If they
    do not exist, any subsequence access will fail as usual, after the
    deprecation warning is given.

    Parameters
    ----------
    key : str
        Name of the option to be deprecated.
        must be a fully-qualified option name (e.g "x.y.z.rkey").
    msg : str, optional
        Warning message to output when the key is referenced.
        if no message is given a default message will be emitted.
    rkey : str, optional
        Name of an option to reroute access to.
        If specified, any referenced `key` will be
        re-routed to `rkey` including set/get/reset.
        rkey must be a fully-qualified option name (e.g "x.y.z.rkey").
        used by the default message if no `msg` is specified.
    removal_ver : optional
        Specifies the version in which this option will
        be removed. used by the default message if no `msg` is specified.

    Raises
    ------
    OptionError
        If the specified key has already been deprecated.
    zOption 'z)' has already been defined as deprecated.N)rs�_deprecated_optionsrr)r#r~r��removal_verrrr�deprecate_option�s$r�)rrcs8�tkr�gSttj��}�dkr&|S�fdd�|D�S)zb
    returns a list of keys matching `pat`

    if pat=="all", returns all registered options
    rcs g|]}tj�|tj�r|�qSr)rv�search�I)r@r')rrrrA*sz#_select_options.<locals>.<listcomp>)rG�sortedr")rr"r)rrrsr)r#rcCs8|jd�}t}x|dd�D]}||}qW||dfS)NrSrrprp)rurz)r#r|r}r�rrrr%-s

r%cCs|j�}|tkS)z6 Returns True if the given option has been deprecated )rsr�)r#rrr�_is_deprecated5sr�)r#cCs*yt|}Wntk
r dSX|SdS)z�
    Retrieves the metadata for a deprecated option, if `key` is deprecated.

    Returns
    -------
    DeprecatedOption (namedtuple) if key is deprecated, None otherwise
    N)r�rW)r#rLrrr�_get_deprecated_option;s
r�cCs
tj|�S)z�
    Retrieves the option metadata if `key` is a registered option.

    Returns
    -------
    RegisteredOption (namedtuple) if key is deprecated, None otherwise
    )rG�get)r#rrrr1Ksr1cCst|�}|r|jp|S|SdS)z�
    if key id deprecated and a replacement key defined, will return the
    replacement key, otherwise returns `key` as - is
    N)r�r�)r#rLrrrr!Vs
r!cCs�t|�}|r�|jr,t|j�tj|jt�nPd|�d�}|jrN|d|j��7}|jrh|d|j�d�7}n|d7}tj|t�dSdS)	z�
    Checks if `key` is a deprecated option and if so, prints a warning.

    Returns
    -------
    bool - True if `key` is deprecated, False otherwise.
    �'z' is deprecatedz and will be removed in z, please use 'z
' instead.z, please refrain from using it.TF)r�r~rCr4�warn�
FutureWarningr�r�)r#rLr~rrrrbs
r)r'rcCs�t|�}t|�}|�d�}|jr<|dj|jj�jd��7}n|d7}|rf|d|j�dt|d��d�7}|r�|jrv|jnd}|d	7}|d
|�d�7}|d7}|S)
zE Builds a formatted description of a registered option and prints it � r>zNo description available.z
    [default: z] [currently: T�]r<z
    (Deprecatedz, use `z
` instead.�))	r1r�rlrB�striprurHr(r�)r'r:rLrDr�rrrr?}s
r?�P)r"�_printc
s�ddlm}ddlm�tttttd���fdd�}g}dd�t|�D�}|r`||d	|�7}d
d�|D�}xB|t|�dd��D],\�}�fd
d�t|�D�}||�|�7}q�Wdj	|�}	|r�t
|	�n|	SdS)zB Builds a concise listing of available options, grouped by prefix r)�groupby)�wrap)�name�ksrcsP|rd|dnd}�dj|��|ddd�}|rL|d
rL|rL|dd	|d<|S)
Nz- z.[r<z, z  F)�initial_indent�subsequent_indent�break_long_wordsrr�rprprp)rB)r�r��pfx�ls)�widthr�rr�pp�szpp_options_list.<locals>.ppcSsg|]}|jd�dkr|�qS)rSr)�find)r@�xrrrrA�sz#pp_options_list.<locals>.<listcomp>r<cSsg|]}|jd�dkr|�qS)rSr)r�)r@r�rrrrA�scSs|d|jd��S)NrS)�rfind)r�rrr�<lambda>�sz!pp_options_list.<locals>.<lambda>cs g|]}|t��dd��qS)rN)r)r@r�)r'rrrA�sr>N)�	itertoolsr��textwrapr�r[rr	r�r.rBrC)
r"r�r�r�r�r�Zsingles�gr�rDr)r'r�r�rrd�s 


rdc#sNttd��fdd�}t}t}t}|t�a|t�a|t�adV|a|a|adS)a�
    contextmanager for multiple invocations of API with a common prefix

    supported API functions: (register / get / set )__option

    Warning: This is not thread - safe, and won't work properly if you import
    the API functions into your module using the "from x import y" construct.

    Example
    -------
    import pandas._config.config as cf
    with cf.config_prefix("display.font"):
        cf.register_option("color", "red")
        cf.register_option("size", " 5 pt")
        cf.set_option(size, " 6 pt")
        cf.get_option(size)
        ...

        etc'

    will register options "display.font.color", "display.font.size", set the
    value of "display.font.size"... and so on.
    )r_rcstd���fdd�}tt|�S)N)r#cs��d|��}�|f|�|�S)NrSr)r#r6r`Zpkey)r_rMrr�inner�sz*config_prefix.<locals>.wrap.<locals>.inner)r[r
r)r_r�)rM)r_rr��szconfig_prefix.<locals>.wrapN)rr��
get_option�
set_option)rMr�Z_register_optionr(r;r)rMr�
config_prefix�sr�)�_typercsdd��fdd�}|S)a

    Parameters
    ----------
    `_type` - a type to be compared against (e.g. type(x) == `_type`)

    Returns
    -------
    validator - a function of a single argument x , which raises
                ValueError if type(x) is not equal to `_type`

    N)rcs t|��krtd��d���dS)NzValue must have type 'r�)�typer,)r�)r�rrr��szis_type_factory.<locals>.innerr)r�r�r)r�r�is_type_factory�sr�csLt�ttf�r(t���djtt����nd��d��dd���fdd�}|S)z�

    Parameters
    ----------
    `_type` - the type to be checked against

    Returns
    -------
    validator - a function of a single argument x , which raises
                ValueError if x is not an instance of `_type`

    �|r�N)rcst|��std�����dS)NzValue must be an instance of )rUr,)r�)r��	type_reprrrr�s
z"is_instance_factory.<locals>.inner)rU�tupler.rB�mapr[)r�r�r)r�r�r�is_instance_factorys
r�cs4dd��D��dd��D��dd���fdd�}|S)NcSsg|]}t|�r|�qSr)�callable)r@�crrrrA!sz%is_one_of_factory.<locals>.<listcomp>cSsg|]}t|�s|�qSr)r�)r@r�rrrrA"s)rcs\��krXt�fdd��D��sXdd��D�}dj|�}d|��}t��rP|d7}t|��dS)Nc3s|]}|��VqdS)Nr)r@r�)r�rr�	<genexpr>'sz3is_one_of_factory.<locals>.inner.<locals>.<genexpr>cSsg|]}t|��qSr)r[)r@ZlvalrrrrA(sz4is_one_of_factory.<locals>.inner.<locals>.<listcomp>r�zValue must be one of z or a callable)�anyrBrr,)r�ZuvalsZ	pp_valuesr~)�	callables�legal_values)r�rr�$s

z is_one_of_factory.<locals>.innerr)r�r�r)r�r�r�is_one_of_factorysr�)�valuercCs2|dkrdSt|t�r"|dkr"dSd}t|��dS)z�
    Verify that value is None or a positive int.

    Parameters
    ----------
    value : None or int
            The `value` to be checked.

    Raises
    ------
    ValueError
        When the value is not None or is a negative integer
    Nrz+Value must be a nonnegative integer or None)rU�intr,)r�r~rrr�is_nonnegative_int2s
r�cCst|�std��dS)z�

    Parameters
    ----------
    `obj` - the object to be checked

    Returns
    -------
    validator - returns True if object is callable
        raises ValueError otherwise.

    zValue must be a callableT)r�r,)�objrrr�is_callableTs
r�)F)r<T)F)r<NN)NNN)r�F)Kr�collectionsr�
contextlibrrrvZtypingrrrrr	r
rrr
r4Zpandas._typingrrrr�r[rGrzrt�AttributeErrorrWr�boolr$r(r;rErIrJrKr\Z_get_option_tmplZ_set_option_tmplZ_describe_option_tmplZ_reset_option_tmplr�r�Zreset_optionZdescribe_option�optionsrgrNr�r�rr%r�r�r1r!rr?rdr�r�r�r�r�r�Zis_intZis_bool�floatZis_floatZis_str�bytesZis_textr�rrrr�<module>1sr,

 .-" 



#(H. &5