
    M/Phu8                         d dl mZmZ d dlmZ d dlZd dlZddZ	ej
        dddddddfdZ G d	 d
          ZddZ	 ddededededee         f
dZddedededefdZddZddZddZdS )    )AnyOptional)MappingNc                     | j         }t          | j                  D ]}|dk    r n|dz  }t          ||          }|                     | j        d|                   S )a  
    Remove trailing singleton dimensions

    Parameters
    ----------
    arr : ndarray
        Input array
    stop_dim : int
        Dimension where checking should stop so that shape[i] is not checked
        for i < stop_dim

    Returns
    -------
    squeezed : ndarray
        Array with all trailing singleton dimensions (0 or 1) removed.
        Singleton dimensions for dimension < stop_dim are retained.
       N)ndimreversedshapemaxreshape)arrstop_dimlastss       g/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/tools/validation/validation.py_right_squeezer      si    $ 8Dci    q55E	tXD;;sy$'(((    r   FTc
                    |r| dS |	rdgng }
|dk    s|r|
dgz  }
n|dk    r|
dgz  }
t          j        | ||
          }|"|j        |k    r| d| }t          |          n||j        |k    rt	          ||          }n3|j        |k     r(t          j        ||j        d||j        z
  z  z             }|j        |k    r+d	}t          |                    |||j                            |qt          |j        |          D ][\  }}|T||k    rNt          |          
                    d
d          }d}t          |                    |||j                            \|S )aD  
    Convert array-like to a ndarray and check conditions

    Parameters
    ----------
    obj : array_like
         An array, any object exposing the array interface, an object whose
        __array__ method returns an array, or any (nested) sequence.
    name : str
        Name of the variable to use in exceptions
    dtype : {None, numpy.dtype, str}
        Required dtype. Default is double. If None, does not change the dtype
        of obj (if present) or uses NumPy to automatically detect the dtype
    ndim : {int, None}
        Required number of dimensions of obj. If None, no check is performed.
        If the number of dimensions of obj is less than ndim, additional axes
        are inserted on the right. See examples.
    maxdim : {int, None}
        Maximum allowed dimension.  Use ``maxdim`` instead of ``ndim`` when
        inputs are allowed to have ndim 1, 2, ..., or maxdim.
    shape : {tuple[int], None}
        Required shape obj.  If None, no check is performed. Partially
        restricted shapes can be checked using None. See examples.
    order : {'C', 'F', None}
        Order of the array
    contiguous : bool
        Ensure that the array's data is contiguous with order ``order``
    optional : bool
        Flag indicating whether None is allowed
    writeable : bool
        Whether to ensure the returned array is writeable

    Returns
    -------
    ndarray
        The converted input.

    Examples
    --------
    Convert a list or pandas series to an array
    >>> import pandas as pd
    >>> x = [0, 1, 2, 3]
    >>> a = array_like(x, 'x', ndim=1)
    >>> a.shape
    (4,)

    >>> a = array_like(pd.Series(x), 'x', ndim=1)
    >>> a.shape
    (4,)

    >>> type(a.orig)
    pandas.core.series.Series

    Squeezes singleton dimensions when required
    >>> x = np.array(x).reshape((4, 1))
    >>> a = array_like(x, 'x', ndim=1)
    >>> a.shape
    (4,)

    Right-appends when required size is larger than actual
    >>> x = [0, 1, 2, 3]
    >>> a = array_like(x, 'x', ndim=2)
    >>> a.shape
    (4, 1)

    Check only the first and last dimension of the input
    >>> x = np.arange(4*10*4).reshape((4, 10, 4))
    >>> y = array_like(x, 'x', ndim=3, shape=(4, None, 4))

    Check only the first two dimensions
    >>> z = array_like(x, 'x', ndim=3, shape=(4, 10))

    Raises ValueError if constraints are not satisfied
    >>> z = array_like(x, 'x', ndim=2)
    Traceback (most recent call last):
     ...
    ValueError: x is required to have ndim 2 but has ndim 3

    >>> z = array_like(x, 'x', shape=(10, 4, 4))
    Traceback (most recent call last):
     ...
    ValueError: x is required to have shape (10, 4, 4) but has shape (4, 10, 4)

    >>> z = array_like(x, 'x', shape=(None, 4, 4))
    Traceback (most recent call last):
     ...
    ValueError: x is required to have shape (*, 4, 4) but has shape (4, 10, 4)
    NWCF)dtyperequirementsz must have ndim <= )r   )r   z1{0} is required to have ndim {1} but has ndim {2}zNone, z*, z3{0} is required to have shape {1} but has shape {2})nprequirer   
ValueErrorr   r   r
   formatzipstrreplace)objnamer   r   maxdimr
   order
contiguousoptional	writeablereqsr   msgactualreq	req_shapes                   r   
array_liker-   $   s   H  CKt%C552D||z|	#
*SD
9
9
9C8f66f66CS//!  
	8d?? t444CCX__*S#)ddSXo.F"FGGC8tECSZZdCH==>>>sy%00 	I 	IKFC6S==JJ..x??	K D)SY!G!GHHHJr   c                        e Zd ZdZd ZddZdS )PandasWrappera  
    Wrap array_like using the index from the original input, if pandas

    Parameters
    ----------
    pandas_obj : {Series, DataFrame}
        Object to extract the index from for wrapping

    Notes
    -----
    Raises if ``orig`` is a pandas type but obj and and ``orig`` have
    different numbers of elements in axis 0. Also raises if the ndim of obj
    is larger than 2.
    c                 j    || _         t          |t          j        t          j        f          | _        d S )N)_pandas_obj
isinstancepdSeries	DataFrame
_is_pandas)self
pandas_objs     r   __init__zPandasWrapper.__init__   s(    %$Z")R\1JKKr   Nr   c                    t          j        |          }| j        s|S |j        d         |z   |z   | j        j        d         k    rt          d          | j        j        }|||j        d         |z
           }|j        dk    r]|t          | j        dd          }n t          |t                    r|}n|d         }|||n| d| }t          j        |||          S |j        dk    rX|t          | j        d	d          }|'g }|D ] }	|                    |	|n|	 d|            !|}t          j        |||
          S t          d          )a	  
        Parameters
        ----------
        obj : {array_like}
            The value to wrap like to a pandas Series or DataFrame.
        columns : {str, list[str]}
            Column names or series name, if obj is 1d.
        append : str
            String to append to the columns to create a new column name.
        trim_start : int
            The number of observations to drop from the start of the index, so
            that the index applied is index[trim_start:].
        trim_end : int
            The number of observations to drop from the end of the index , so
            that the index applied is index[:nobs - trim_end].

        Returns
        -------
        array_like
            A pandas Series or DataFrame, depending on the shape of obj.
        r   z;obj must have the same number of elements in axis 0 as origr   Nr"   _)r"   index   columns)r>   r<   z!Can only wrap 1 or 2-d array_like)r   asarrayr6   r
   r1   r   r<   r   getattrr2   r   r3   r4   appendr5   )
r7   r!   r>   rA   
trim_starttrim_endr<   r"   newcs
             r   wrapzPandasWrapper.wrap   s   , joo 	J9Q<*$x/43C3I!3LLL!    &j%+a.8";;<8q==t/>>GS)) "qz!!%vvd3E3EV3E3E9St59999X]]!$"2ItDD!  I IAJJvv1vHHHH<WEBBBB@AAAr   )NNr   r   )__name__
__module____qualname____doc__r9   rF    r   r   r/   r/      sJ         L L L6B 6B 6B 6B 6B 6Br   r/   c                 f   |r| | S |rdnd}|r+t          | t                    r| S t          | d|           t          | d          r(t	          | j                  r|                                 } 	 t          |           S # t          $ r$ t          d                    ||                    w xY w)a  
    Convert to bool or raise if not bool_like

    Parameters
    ----------
    value : object
        Value to verify
    name : str
        Variable name for exceptions
    optional : bool
        Flag indicating whether None is allowed
    strict : bool
        If True, then only allow bool. If False, allow types that support
        casting to bool.

    Returns
    -------
    converted : bool
        value converted to a bool
    N or None z must be a boolsqueezez({} must be a bool (or bool-compatible){})r2   bool	TypeErrorhasattrcallablerO   	Exceptionr   )valuer"   r&   strict
extra_texts        r   	bool_likerX      s    *  EM'/RJ BeT"" 	BLt@@J@@AAAui    Xem%<%<  
E{{ 
 
 
j))
 
 	

s   3B .B0rU   r"   r&   rV   returnc                    |r| dS t          | t          t          j        f          }t	          | d          r(t          | j                  r|                                 } t          | t          t          j        f          r|st          |           S |s,|s*	 | | dz  k    rt          |           S n# t          $ r Y nw xY w|rdnd}t          d                    ||                    )  
    Convert to int or raise if not int_like

    Parameters
    ----------
    value : object
        Value to verify
    name : str
        Variable name for exceptions
    optional : bool
        Flag indicating whether None is allowed
    strict : bool
        If True, then only allow int or np.integer that are not bool. If False,
        allow types that support integer division by 1 and conversion to int.

    Returns
    -------
    converted : int
        value converted to a int
    NrO   r   rM   rN   zJ{} must be integer_like (int or np.integer, but not bool or timedelta64){})r2   rP   r   timedelta64rR   rS   rO   intintegerrT   rQ   r   )rU   r"   r&   rV   is_bool_timedeltarW   s         r   int_liker`     s   .  EMt"54*@AAui    Xem%<%<  %#rz*++ 4E 5zz - 	!$$5zz! % 	 	 	D	'/RJ
	#VD*55  s   B0 0
B=<B=c                 4    t          | |d|          }|J |S )r[   F)r&   rV   )r`   )rU   r"   rV   _ints       r   required_int_likerc   H  s+    * E4%???DKr   c                    |r| dS t          | t                    }t          | t          t          j        f          }t          | d          r(t          | j                  r|                                 } t          | t          t          j	        t          t          j        f          r|s|st          |           S |s>|r<t          j        |           }|dk    r!t          t          j        |                     S n'|s%|s#	 t          | dz            S # t          $ r Y nw xY w|rdnd}t          d                    ||                    )aw  
    Convert to float or raise if not float_like

    Parameters
    ----------
    value : object
        Value to verify
    name : str
        Variable name for exceptions
    optional : bool
        Flag indicating whether None is allowed
    strict : bool
        If True, then only allow int, np.integer, float or np.inexact that are
        not bool or complex. If False, allow complex types with 0 imag part or
        any other type that is float like in the sense that it support
        multiplication by 1.0 and conversion to float.

    Returns
    -------
    converted : float
        value converted to a float
    NrO   r   g      ?rM   rN   z-{} must be float_like (float or np.inexact){})r2   rP   complexr   complexfloatingrR   rS   rO   r]   r^   floatinexactimagrealrT   rQ   r   )rU   r"   r&   rV   is_bool
is_complexri   rW   s           r   
float_likerm   b  sb   .  EMt%%GEGR-?#@AAJui    Xem%<%<  %#rz5"*=>>  U|| 
 wu~~199(((  G 	%%% 	 	 	D	'/RJ
	VD*%%  s   ?D 
DDc                 2   | dS t          | t                    s|rdnd}t          | d|           |r|                                 } |K| |vrG|rdnd}dd                    |          z   dz   }d                    |||          }t          |          | S )	a  
    Check if object is string-like and raise if not

    Parameters
    ----------
    value : object
        Value to verify.
    name : str
        Variable name for exceptions.
    optional : bool
        Flag indicating whether None is allowed.
    options : tuple[str]
        Allowed values for input parameter `value`.
    lower : bool
        Convert all case-based characters in `value` into lowercase.

    Returns
    -------
    str
        The validated input

    Raises
    ------
    TypeError
        If the value is not a string or None when optional is True.
    ValueError
        If the input is not in ``options`` when ``options`` is set.
    NrM   rN   z must be a stringIf not None, 'z', 'z{}{} must be one of: {})r2   r   rQ   lowerjoinr   r   )rU   r"   r&   optionsrq   rW   options_textr)   s           r   string_likeru     s    : }teS!! @#+3ZZ
4>>*>>??? uG33(08__b
V[[111C7'..l
 
 ooLr   c                     |r| dS t          | t                    r|r9t          | t                    s$|rdnd}|rdnd}| | d| }t          |          | S )a  
    Check if dict_like (dict, Mapping) or raise if not

    Parameters
    ----------
    value : object
        Value to verify
    name : str
        Variable name for exceptions
    optional : bool
        Flag indicating whether None is allowed
    strict : bool
        If True, then only allow dict. If False, allow any Mapping-like object.

    Returns
    -------
    converted : dict_like
        value
    Nro   rN   z or dict_like (i.e., a Mapping)z must be a dict)r2   r   dictrQ   )rU   r"   r&   rV   rW   strict_textr)   s          r   	dict_likery     s    (  EMteW%% "5$// )18__b
;AI77r?T??+??nnLr   )r   )FF)F)FNT)FT)typingr   r   collections.abcr   numpyr   pandasr3   r   doubler-   r/   rX   r   rP   r]   r`   rc   rm   ru   ry   rK   r   r   <module>r      s                   # # # # # #        ) ) ) )> )	


~ ~ ~ ~BJB JB JB JB JB JB JB JBZ&
 &
 &
 &
T CH* ***%)*;?*c]* * * *Z S  T c    4/ / / /d+ + + +\     r   