o
    iv5                  	   @  s  U d Z ddlmZ ddlZddlmZ ddlmZmZmZ ddl	m
Z
mZmZmZ ddlm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mZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% dd
l&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZD ddlEmFZF ddlGmHZHmIZI e
rddlmJZJ ddlmKZKmLZL ddlmMZM ddlNmOZOmPZPmQZQ ddl&mRZRmSZSmTZT dZUdZVeWeeeWeeeWeeeWeeeWe edeWde!eWde"eWde#eWde$eWde%ddZXdeYd< 	dudddvd!d"ZW	duddd#dwd(d)ZZdxd+d,Z[dyd.d/Z\dzd1d2Z]eVfd{d5d6Z^d|d8d9Z_d}d;d<Z`	d~ddCdDZadddFdGZb	dddMdNZcddddOdPdd[d\Zddd]ddbdcZeddedfZfddhdiZgi e*e[ e5eWdjdde6eWdkdde7eWdldde8eWddde9eWdmdde@eWdjdOdeAeWdkdOdeBeWdldOdeCeWddOdeDeWdmdOde?e_ e,e` e=e\ e)e] e;ef e<eg ZhdneYdo< dOd]ddsdtZidS )z0Strategies for generating various forms of data.    )annotationsN)Mapping)datetime	timedeltatimezone)TYPE_CHECKINGAnyLiteralcast)ZoneInfo)InvalidArgument)EPOCHI8_MAXI8_MINI16_MAXI16_MINI32_MAXI32_MINI64_MAXI64_MINI128_MAXI128_MINU8_MAXU16_MAXU32_MAXU64_MAXU128_MAX)ArrayBaseExtensionBinaryBooleanCategoricalDateDatetimeDecimalDurationEnumFieldFloat16Float32Float64Int8Int16Int32Int64Int128ListNullObjectStringStructTimeUInt8UInt16UInt32UInt64UInt128)flexhash)_DEFAULT_ARRAY_WIDTH_LIMIT_DEFAULT_ENUM_CATEGORIES_LIMIT)Sequence)datetime)SearchStrategy)PolarsDataType
SchemaDictTimeUnit)DataTypeDataTypeClass	FloatType   
   )          @      )TFz*dict[bool, dict[int, SearchStrategy[int]]]_INTEGER_STRATEGIESrM   T)signed	bit_widthLiteral[8, 16, 32, 64, 128]rP   boolreturnSearchStrategy[int]c                C  s   t | |  S )*Create a strategy for generating integers.)rO   )rQ   rP    rW   `/home/app/Keep/.python/lib/python3.10/site-packages/polars/testing/parametric/strategies/data.pyintegersd   s   rY   )	allow_nanallow_infinityLiteral[16, 32, 64]rZ   r[   SearchStrategy[float]c                C  s   t j| ||dS )rV   )widthrZ   r[   )stfloatsrQ   rZ   r[   rW   rW   rX   r`   k   s   r`   SearchStrategy[bool]c                   C     t  S )z*Create a strategy for generating booleans.)r_   booleansrW   rW   rW   rX   rd   w      rd   SearchStrategy[str]c                  C  s    t jdddgd} t j| ddS )z/Create a strategy for generating string values.  CsCc)Zmax_codepointZexclude_categoriesrJ   )alphabetmax_size)r_   
characterstext)rj   rW   rW   rX   strings|   s   rn   SearchStrategy[bytes]c                   C  rc   )z'Create a strategy for generating bytes.)r_   binaryrW   rW   rW   rX   rp      re   rp   n_categoriesintc                 C  s   dd t | D }t|S )z
    Create a strategy for generating category strings.

    Parameters
    ----------
    n_categories
        The number of categories.
    c                 S  s   g | ]}d | qS )crW   ).0irW   rW   rX   
<listcomp>   s    zcategories.<locals>.<listcomp>)ranger_   sampled_from)rq   
categoriesrW   rW   rX   ry      s   	
ry   SearchStrategy[time]c                   C  rc   )z0Create a strategy for generating `time` objects.)r_   timesrW   rW   rW   rX   r{      re   r{   SearchStrategy[date]c                   C  rc   )z0Create a strategy for generating `date` objects.)r_   datesrW   rW   rW   rX   r}      re   r}   us	time_unitrD   	time_zone
str | NoneSearchStrategy[datetime]c                 C  s   | dv rt j}t j}n"| dkr$tttd d d }tttd d }n	d| }t||du r7t	||S t
|}| dkrM|tdd7 }|tdd8 }tj	||t|d	d
dd S )a
  
    Create a strategy for generating `datetime` objects in the time unit's range.

    Parameters
    ----------
    time_unit
        Time unit for which the datetime objects are valid.
    time_zone
        Time zone for which the datetime objects are valid.
    )r~   msnsrg      microsecondsinvalid time unit: N)daysF)	min_value	max_valueZ	timezonesZallow_imaginaryc                 S  s   |  tjjd dS )N)tzinfo)
astimezoner   utcreplace)dtrW   rW   rX   <lambda>   s    zdatetimes.<locals>.<lambda>)r   minmaxr   r   r   r   r   r_   	datetimesr   Zjustmap)r   r   r   r   msgZtime_zone_inforW   rW   rX   r      s,   

r   SearchStrategy[timedelta]c                 C  s   | dkrt jttdttddS | dkr&t jttd dttd ddS | dkr7t jttdttddS d| }t|)z
    Create a strategy for generating `timedelta` objects in the time unit's range.

    Parameters
    ----------
    time_unit
        Time unit for which the timedelta objects are valid.
    r~   r   )r   r   r   rg   r   r   )r_   Z
timedeltasr   r   r   r   )r   r   rW   rW   rX   	durations   s"   	
r   &   	precision
int | NonescaleSearchStrategy[decimal.Decimal]c                 C  sT   | du rd} t j| d}|d| |  }||}||}tj||dd|dS )aH  
    Create a strategy for generating `Decimal` objects.

    Parameters
    ----------
    precision
        Maximum number of digits in each number.
        If set to `None`, the precision is set to 38 (the maximum supported by Polars).
    scale
        Number of digits to the right of the decimal point in each number.
    Nr   )precz1E+F)r   r   rZ   r[   Zplaces)decimalContextcreate_decimal
next_minuscopy_negater_   decimals)r   r   rs   Zexclusive_limitr   r   rW   rW   rX   r      s   

r   Fselect_frommin_sizerk   uniqueinner_dtyperE   r   Sequence[Any] | Noner   rk   r   kwargsr   SearchStrategy[list[Any]]c                K  sp   |du r|dkr
t n|d }|dur|  st|}nt| f||||d|}tj||||r4tdS ddS )aD  
    Create a strategy for generating lists of the given data type.

    .. warning::
        This functionality is currently considered **unstable**. It may be
        changed at any point without it being considered a breaking change.

    Parameters
    ----------
    inner_dtype
        Data type of the list elements. If the data type is not fully instantiated,
        defaults will be used, e.g. `Datetime` will become `Datetime('us')`.
    select_from
        The values to use for the innermost lists. If set to `None` (default),
        the default strategy associated with the innermost data type is used.
    min_size
        The minimum length of the generated lists.
    max_size
        The maximum length of the generated lists. If set to `None` (default), the
        maximum is set based on `min_size`: `3` if `min_size` is zero,
        otherwise `2 * min_size`.
    unique
        Ensure that the generated lists contain unique values.
    **kwargs
        Additional arguments that are passed to nested data generation strategies.

    Examples
    --------
    ...
    Nr      r   )elementsr   rk   Z	unique_by)_DEFAULT_LIST_LEN_LIMITZ	is_nestedr_   rx   datalistsr;   )r   r   r   rk   r   r   Zinner_strategyrW   rW   rX   r     s,   '	r   
allow_nullfieldsSequence[Field] | SchemaDictr   SearchStrategy[dict[str, Any]]c                  sL   t | trdd |  D }  fdd| D } r!tji |dS t|S )a  
    Create a strategy for generating structs with the given fields.

    Parameters
    ----------
    fields
        The fields that make up the struct. Can be either a sequence of Field
        objects or a mapping of column names to data types.
    allow_null
        Allow nulls as possible values. If set to True, the returned dictionaries
        may miss certain fields and are in random order.
    **kwargs
        Additional arguments that are passed to nested data generation strategies.
    c                 S  s   g | ]	\}}t ||qS rW   )r'   )rt   namedtyperW   rW   rX   rv   Z  s    zstructs.<locals>.<listcomp>c                   s&   i | ]}|j t|jfd  iqS r   )r   r   r   )rt   fr   r   rW   rX   
<dictcomp>\  s   & zstructs.<locals>.<dictcomp>)optional)
isinstancer   itemsr_   Zfixed_dictionaries)r   r   r   ZstratsrW   r   rX   structsE  s   

r   SearchStrategy[None]c                   C  rc   )z-Create a strategy for generating null values.)r_   nonerW   rW   rW   rX   nullsd  re   r   SearchStrategy[object]c                   C  s
   t tS )z3Create a strategy for generating arbitrary objects.)r_   ZbuildsobjectrW   rW   rW   rX   objectsi  s   
r   rJ   rK   rL   rN   z(dict[DataTypeClass, SearchStrategy[Any]]_STATIC_STRATEGIESr   rB   SearchStrategy[Any]c          
      K  sJ  t |   }dur|}n|  r7td| } tdtdtdit|  }t	td||
dd|
d	dd
}n| tkrLtt| ddpCdt| ddd}n| tkr\tt| ddpXdd}n| tkrjt|
dtd}n| tkrt| tr| j } r~t }nt| }nt|
dtd}n| tkrtt| ddt| dd}ny| tkrt| ddpt }t|fd|i|}na| t krt| ddpt }t| dt!}dd |" D }t|f|||d|}n8| t#krt| ddpt$dt g}t%|fd|i|}nt| t&rt'| ( fd|i|}n	d|  }	t)|	|r#t |B }|S )a  
    Create a strategy for generating data for the given data type.

    Parameters
    ----------
    dtype
        A Polars data type. If the data type is not fully instantiated, defaults will
        be used, e.g. `Datetime` will become `Datetime('us')`.
    allow_null
        Allow nulls as possible values.
    **kwargs
        Additional parameters for the strategy associated with the given `dtype`.
    NrG   rK   rL   rM   r\   rZ   Tr[   ra   r   r~   r   )r   r   )r   rq   )rq   r   r   r   innerr   sizec                 S  s   i | ]\}}|d vr||qS ))r   rk   rW   )rt   kvrW   rW   rX   r     s    zdata.<locals>.<dictcomp>)r   rk   r   r   Zf0zunsupported data type: )*r   getZ	base_typeZis_floatr
   r(   r)   r*   typer`   popr#   r   getattrr%   r   r!   ry   _DEFAULT_N_CATEGORIESr&   r   Zis_emptyr   r_   rx   Zto_listr=   r$   r   r0   r1   r   r   r<   r   r4   r'   r   r   r   Zext_storager   )
r   r   r   ZstrategyrQ   Zcatsr   r   r   r   rW   rW   rX   r     sv   








r   )rM   )rQ   rR   rP   rS   rT   rU   )rQ   r\   rZ   rS   r[   rS   rT   r]   )rT   rb   )rT   rf   )rT   ro   )rq   rr   rT   rf   )rT   rz   )rT   r|   )r~   N)r   rD   r   r   rT   r   )r~   )r   rD   rT   r   )r   r   )r   r   r   rr   rT   r   )r   rE   r   r   r   rr   rk   r   r   rS   r   r   rT   r   )r   r   r   rS   r   r   rT   r   )rT   r   )rT   r   )r   rB   r   rS   r   r   rT   r   )j__doc__
__future__r   r   collections.abcr   r   r   r   typingr   r   r	   r
   zoneinfor   Zhypothesis.strategies
strategiesr_   Zhypothesis.errorsr   Zpolars._utils.constantsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zpolars.datatypesr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   Z+polars.testing.parametric.strategies._utilsr;   Z*polars.testing.parametric.strategies.dtyper<   r=   r>   r?   r@   rA   Zpolars._typingrB   rC   rD   rE   rF   rG   r   r   rY   rO   __annotations__r`   rd   rn   rp   ry   r{   r}   r   r   r   r   r   r   r   r   r   rW   rW   rW   rX   <module>   s    H 














*!"A

	
