a
    jDfQ>                     @   s6  d dl mZmZmZmZ d dlmZmZmZm	Z	m
Z
 zd dlmZ W n. eyr Z zedeW Y dZ[n
dZ[0 0 d dlm  mZ d dlZd dlmZ d dlZd dlmZ erd dlmZmZ g dZG d	d
 d
ee Zejej  dddZ!ejej  dddZ"ej#ddgddZ$eje% dddZ&e& d dde'e'eje(e  dddZ)e& d ddddeje e'e'e'e	e'df ejeee'f  dddZ*ej+e$d d!Z,e,Z-ej.ej/d"d"d#e0 d$Z1e2 e3 B e,B e1B Z4ejeeef  dd%d&Z5ej6dde! e5 d'ej7e	edf e	eje	ee eee'f f  df ejej  eje ej8d(d)d*Z9e
d dd+ee e'e	e'df ejee  d,d-d.Z:e
d dd+eeef e'e	e'df ejeeef  d,d/d.Z:ej6d dd+ej7e	ee eeef f e'e	e'df e	ee eeef f d0d1d.Z:dS )2    )HashableIterableMappingSequence)TYPE_CHECKINGAnyProtocolUnionoverloadNzB`xarray.testing.strategies` requires `hypothesis` to be installed.)InvalidArgument)T_DuckArray)_DTypeLikeNested
_ShapeLike)supported_dtypespandas_index_dtypesnamesdimension_namesdimension_sizesattrs	variablesunique_subset_ofc                   @   s$   e Zd Zddeje dddZdS )ArrayStrategyFnr   r   )shapedtypereturnc                C   s   d S N )selfr   r   r   r   f/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/xarray/testing/strategies.py__call__#   s    zArrayStrategyFn.__call__N)__name__
__module____qualname__stSearchStrategyr   r   r   r   r   r   r   "   s   r   )r   c                   C   s0   t jddt jddB t jddB t jddB S )a  
    Generates only those numpy dtypes which xarray can handle.

    Use instead of hypothesis.extra.numpy.scalar_dtypes in order to exclude weirder dtypes such as unicode, byte_string, array, or nested dtypes.
    Also excludes datetimes, which dodges bugs with pandas non-nanosecond datetime overflows.  Checks only native endianness.

    Requires the hypothesis package to be installed.

    See Also
    --------
    :ref:`testing.hypothesis`_
    =
endianness)npstinteger_dtypesunsigned_integer_dtypesfloating_dtypesZcomplex_number_dtypesr   r   r   r   r   +   s    



r   c                   C   sR   t jdddt jdddB t jdddB t jdddB t jdddB t jddB S )z
    Dtypes supported by pandas indexes.
    Restrict datetime64 and timedelta64 to ns frequency till Xarray relaxes that.
    r%   )    @   )r'   sizesns)r'   Z
max_periodr&   )r(   r)   r*   r+   Zdatetime64_dtypesZtimedelta64_dtypesZunicode_string_dtypesr   r   r   r   r   E   s    
r   LNi  )
categoriesZmax_codepointc                   C   s   t jtdddS )z
    Generates arbitrary string names for dimensions / variables.

    Requires the hypothesis package to be installed.

    See Also
    --------
    :ref:`testing.hypothesis`_
          min_sizemax_size)r#   text_readable_charactersr   r   r   r   r   \   s
    
r      Zname_strategymin_dimsmax_dims)r<   r=   r   c                 C   s   t j| ||ddS )at  
    Generates an arbitrary list of valid dimension names.

    Requires the hypothesis package to be installed.

    Parameters
    ----------
    name_strategy
        Strategy for making names. Useful if we need to share this.
    min_dims
        Minimum number of dimensions in generated list.
    max_dims
        Maximum number of dimensions in generated list.
    T)elementsr6   r7   unique)r#   listsr;   r   r   r   r   m   s    r   r3   	dim_namesr<   r=   min_sidemax_side)rB   r<   r=   rC   rD   r   c                 C   s,   |du r|d }t j| t j||d||dS )a  
    Generates an arbitrary mapping from dimension names to lengths.

    Requires the hypothesis package to be installed.

    Parameters
    ----------
    dim_names: strategy generating strings, optional
        Strategy for generating dimension names.
        Defaults to the `names` strategy.
    min_dims: int, optional
        Minimum number of dimensions in generated list.
        Default is 1.
    max_dims: int, optional
        Maximum number of dimensions in generated list.
        Default is 3.
    min_side: int, optional
        Minimum size of a dimension.
        Default is 1.
    max_side: int, optional
        Minimum size of a dimension.
        Default is `min_length` + 5.

    See Also
    --------
    :ref:`testing.hypothesis`_
    Nr:   )Z	min_valueZ	max_value)keysvaluesr6   r7   )r#   dictionariesZintegersrA   r   r   r   r      s    $r   r4   )r7      )rD   r=   r   r   c                   C   s   t jt ttdd ddS )z
    Generates arbitrary valid attributes dictionaries for xarray objects.

    The generated dictionaries can potentially be recursive.

    Requires the hypothesis package to be installed.

    See Also
    --------
    :ref:`testing.hypothesis`_
    c                 S   s   t t| S r   )r#   rG   
_attr_keys)childrenr   r   r   <lambda>       zattrs.<locals>.<lambda>r:   )Z
max_leaves)r#   	recursiverG   rJ   _attr_valuesr   r   r   r   r      s
    
r   )array_strategy_fndimsr   r   )drawrP   rQ   r   r   r   c                C   s  t |tjs(|dur(tdt| dt |tjsP|durPtdt| dt |tjsx|durxtdt| d|du rtj}nt|stdn|}| |}|durB| |}t |trt	|}tj
t|t|d}	| |	}
||
|d}nJt |ttfr.t	| t|  }}
||
|d}ntd	t| n0| t
 }
||
|d}| tt|
t|
d}| |}|j|
krtd
|
 d|j d|j|krtd| d|j dtj||| |dS )u  
    Generates arbitrary xarray.Variable objects.

    Follows the basic signature of the xarray.Variable constructor, but allows passing alternative strategies to
    generate either numpy-like array data or dimensions. Also allows specifying the shape or dtype of the wrapped array
    up front.

    Passing nothing will generate a completely arbitrary Variable (containing a numpy array).

    Requires the hypothesis package to be installed.

    Parameters
    ----------
    array_strategy_fn: Callable which returns a strategy generating array-likes, optional
        Callable must only accept shape and dtype kwargs, and must generate results consistent with its input.
        If not passed the default is to generate a small numpy array with one of the supported_dtypes.
    dims: Strategy for generating the dimensions, optional
        Can either be a strategy for generating a sequence of string dimension names,
        or a strategy for generating a mapping of string dimension names to integer lengths along each dimension.
        If provided as a mapping the array shape will be passed to array_strategy_fn.
        Default is to generate arbitrary dimension names for each axis in data.
    dtype: Strategy which generates np.dtype objects, optional
        Will be passed in to array_strategy_fn.
        Default is to generate any scalar dtype using supported_dtypes.
        Be aware that this default set of dtypes includes some not strictly allowed by the array API standard.
    attrs: Strategy which generates dicts, optional
        Default is to generate a nested attributes dictionary containing arbitrary strings, booleans, integers, Nones,
        and numpy arrays.

    Returns
    -------
    variable_strategy
        Strategy for generating xarray.Variable objects.

    Raises
    ------
    ValueError
        If a custom array_strategy_fn returns a strategy which generates an example array inconsistent with the shape
        & dtype input passed to it.

    Examples
    --------
    Generate completely arbitrary Variable objects backed by a numpy array:

    >>> variables().example()  # doctest: +SKIP
    <xarray.Variable (żō: 3)>
    array([43506,   -16,  -151], dtype=int32)
    >>> variables().example()  # doctest: +SKIP
    <xarray.Variable (eD: 4, ğŻżÂĕ: 2, T: 2)>
    array([[[-10000000., -10000000.],
            [-10000000., -10000000.]],
           [[-10000000., -10000000.],
            [        0., -10000000.]],
           [[        0., -10000000.],
            [-10000000.,        inf]],
           [[       -0., -10000000.],
            [-10000000.,        -0.]]], dtype=float32)
    Attributes:
        śřĴ:      {'ĉ': {'iĥf': array([-30117,  -1740], dtype=int16)}}

    Generate only Variable objects with certain dimension names:

    >>> variables(dims=st.just(["a", "b"])).example()  # doctest: +SKIP
    <xarray.Variable (a: 5, b: 3)>
    array([[       248, 4294967295, 4294967295],
           [2412855555, 3514117556, 4294967295],
           [       111, 4294967295, 4294967295],
           [4294967295, 1084434988,      51688],
           [     47714,        252,      11207]], dtype=uint32)

    Generate only Variable objects with certain dimension names and lengths:

    >>> variables(dims=st.just({"a": 2, "b": 1})).example()  # doctest: +SKIP
    <xarray.Variable (a: 2, b: 1)>
    array([[-1.00000000e+007+3.40282347e+038j],
           [-2.75034266e-225+2.22507386e-311j]])

    See Also
    --------
    :ref:`testing.hypothesis`_
    Nz_dims must be provided as a hypothesis.strategies.SearchStrategy object (or None), but got type z>. To specify fixed contents, use hypothesis.strategies.just().z`dtype must be provided as a hypothesis.strategies.SearchStrategy object (or None), but got type z`attrs must be provided as a hypothesis.strategies.SearchStrategy object (or None), but got type zarray_strategy_fn must be a Callable that accepts the kwargs dtype and shape and returns a hypothesis strategy which generates corresponding array-like objects.)r<   r=   rI   z@Invalid type returned by dims strategy - drew an object of type z\array_strategy_fn returned an array object with a different shape than it was passed.Passed z, but returned z.Please either specify a consistent shape via the dims kwarg or ensure the array_strategy_fn callable obeys the shape argument passed to it.z\array_strategy_fn returned an array object with a different dtype than it was passed.Passed zPlease either specify a consistent dtype via the dtype kwarg or ensure the array_strategy_fn callable obeys the dtype argument passed to it.)rQ   datar   )
isinstancer#   r$   r   typer(   arrayscallabler   listarray_shapeslenr   dictrE   tuplerF   r   r   
ValueErrorr   xrVariable)rR   rP   rQ   r   r   Z_array_strategy_fnZ_dtypeZ_dimsrB   Zvalid_shapesZ_shapeZarray_strategy_datar   r   r   r      sn    ^

r   r5   )objsr6   r7   r   c                C   s   d S r   r   ra   r6   r7   r   r   r   r     s    r   c                C   s   d S r   r   rb   r   r   r   r     s    )rR   ra   r6   r7   r   c                   s   t  tstdt  t dkr0tdt  trFt  n }| t	j
t	|d||d}t  tr fdd|D S |S )a  
    Return a strategy which generates a unique subset of the given objects.

    Each entry in the output subset will be unique (if input was a sequence) or have a unique key (if it was a mapping).

    Requires the hypothesis package to be installed.

    Parameters
    ----------
    objs: Union[Sequence[Hashable], Mapping[Hashable, Any]]
        Objects from which to sample to produce the subset.
    min_size: int, optional
        Minimum size of the returned subset. Default is 0.
    max_size: int, optional
        Maximum size of the returned subset. Default is the full length of the input.
        If set to 0 the result will be an empty mapping.

    Returns
    -------
    unique_subset_strategy
        Strategy generating subset of the input.

    Examples
    --------
    >>> unique_subset_of({"x": 2, "y": 3}).example()  # doctest: +SKIP
    {'y': 3}
    >>> unique_subset_of(["x", "y"]).example()  # doctest: +SKIP
    ['x']

    See Also
    --------
    :ref:`testing.hypothesis`_
    zJObject to sample from must be an Iterable or a Mapping, but received type r   z'Can't sample from a length-zero object.T)r?   r6   r7   c                    s   i | ]}| | qS r   r   ).0kra   r   r   
<dictcomp>  rM   z$unique_subset_of.<locals>.<dictcomp>)rT   r   	TypeErrorrU   rZ   r]   r   rX   rE   r#   r@   Zsampled_from)rR   ra   r6   r7   rE   Zsubset_keysr   re   r   r     s"    )

);collections.abcr   r   r   r   typingr   r   r   r	   r
   Zhypothesis.strategiesZ
strategiesr#   ImportErroreZhypothesis.extra.numpyextranumpyr(   npZhypothesis.errorsr   Zxarrayr^   Zxarray.core.typesr   r   r   __all__r   r$   r   r   r   
charactersr9   strr   intrX   r   r   r8   Z_readable_stringsrJ   rV   rY   Zscalar_dtypesZ_small_arraysnoneZbooleansrO   r   Z	compositeZDrawFnr_   r   r   r   r   r   r   <module>   s   	
/

 )



