
    :[g                     d   d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZmZmZmZ dddddd	d
ee   dee   dee   dee   dee   de	egef   fdZ edd      deddfd       Z edd      de
eef   fd       Ze edddd      deded   fd              Zy)z Global configuration for XGBoost    N)contextmanager)wraps)AnyCallableDictIteratorOptionalcast   )_F)_LIB_check_callc_strpy_str)header
extra_note
parametersreturnssee_alsor   r   r   r   r   returnc           	      ~     dddt         t           dt        fddt        dt        f fd}|S )aD  Decorator to format docstring for config functions.

    Parameters
    ----------
    header: str
        An introducion to the function
    extra_note: str
        Additional notes
    parameters: str
        Parameters of the function
    returns: str
        Return value
    see_also: str
        Related functions
    a  
    {header}

    Global configuration consists of a collection of parameters that can be applied in the
    global scope. See :ref:`global_config` for the full list of parameters supported in
    the global configuration.

    {extra_note}

    .. versionadded:: 1.4.0
    af  
    Example
    -------

    .. code-block:: python

        import xgboost as xgb

        # Show all messages, including ones pertaining to debugging
        xgb.set_config(verbosity=2)

        # Get current value of global configuration
        # This is a dict containing all parameters in the global configuration,
        # including 'verbosity'
        config = xgb.get_config()
        assert config['verbosity'] == 2

        # Example of using the context manager xgb.config_context().
        # The context manager will restore the previous value of the global
        # configuration upon exiting.
        with xgb.config_context(verbosity=0):
            # Suppress warning caused by model generated with XGBoost version < 1.0.0
            bst = xgb.Booster(model_file='./old_model.bin')
        assert xgb.get_config()['verbosity'] == 2  # old value restored

    Nested configuration context is also supported:

    Example
    -------

    .. code-block:: python

        with xgb.config_context(verbosity=3):
            assert xgb.get_config()["verbosity"] == 3
            with xgb.config_context(verbosity=2):
                assert xgb.get_config()["verbosity"] == 2

        xgb.set_config(verbosity=2)
        assert xgb.get_config()["verbosity"] == 2
        with xgb.config_context(verbosity=3):
            assert xgb.get_config()["verbosity"] == 3
    valuer   c                     | dS | S )N  )r   s    I/var/www/html/bid-api/venv/lib/python3.12/site-packages/xgboost/config.pynone_to_strzconfig_doc.<locals>.none_to_str\   s    ]r--    funcc                     j                                             z          z          z    	      z    _        t               dt        dt        dt        f fd       }t	        t
        |      S )N)r   r   argskwargsr   c                       | i |S Nr   )r!   r"   r   s     r   wrapz6config_doc.<locals>.config_doc_decorator.<locals>.wrapj   s    (((r   )format__doc__r   r   r
   r   )
r   r%   common_exampledoc_templater   r   r   r   r   r   s
   ` r   config_doc_decoratorz(config_doc.<locals>.config_doc_decorator_   s    "6*{:7N    *%& '"	#
 .)* (#$ 	 
t	) 	)s 	)s 	) 
	) B~r   )r	   strr   )	r   r   r   r   r   r*   r(   r)   r   s	   ````` @@@r   
config_docr,      sI    0
L)NV.8C= .S .2 "  "  r   z#
    Set global configuration.
    z
    Parameters
    ----------
    new_config: Dict[str, Any]
        Keyword arguments representing the parameters and their values
            )r   r   
new_configc                      i }| j                         D ]  \  }}|	|||<    t        j                  |      }t        t	        j
                  t        |                   y r$   )itemsjsondumpsr   r   XGBSetGlobalConfigr   )r-   not_nonekvconfigs        r   
set_configr7   s   sU     H  "1=HQK # ZZ!F''f67r   z9
    Get current values of the global configuration.
    zu
    Returns
    -------
    args: Dict[str, Any]
        The list of global parameters and their values
            )r   r   c                      t        j                         } t        t        j                  t        j
                  |                    | j                  }|sJ t        j                  t        |            }|S r$   )
ctypesc_char_pr   r   XGBGetGlobalConfigbyrefr   r0   loadsr   )
config_strr   r6   s      r   
get_configr?      sU     "J''Z(@ABEL5ZZu&FMr   z;
    Context manager for global XGBoost configuration.
    z
    .. note::

        All settings, not just those presently modified, will be returned to their
        previous values when the context manager is exited. This is not thread-safe.
            z
    See Also
    --------
    set_config: Set global XGBoost configuration
    get_config: Get current values of the global configuration
            )r   r   r   r   c               +      K   t               j                         }t        di |  	 d  t        di | y # t        di | w xY ww)Nr   )r?   copyr7   )r-   
old_configs     r   config_contextrC      sA     2 ""$J! Z 
 Z s   $A7 AAA)r'   r9   r0   
contextlibr   	functoolsr   typingr   r   r   r   r	   r
   _typingr   corer   r   r   r   r+   r,   r7   r?   rC   r   r   r   <module>rI      sD   &   %  @ @  2 2
 ! $ $!"c SMc  c  	c 
 c]c  smc  rdBhc L 	
8S 8T 8
8 	
DcN 
 !.! !$ !/ 0!r   