
    .h4              	         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 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.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZA ddlBmCZC ddlDmEZEmFZF e
r&ddlmGZG ddlmHZHmIZI ddlmJZJ ddlKmLZLmMZMmNZN ddl%mOZOmPZP dZQdZR ej                  ee       ej                  ee       ej                  ee       ej                  ee       ej                  ee      d ej                  de        ej                  de!       ej                  de"       ej                  de#       ej                  de$      ddZTdeUd<   	 d5dd	 	 	 	 	 d6dZS	 d5ddd	 	 	 	 	 	 	 d7dZVd8dZWd9dZXd:d ZYeRfd;d!ZZd<d"Z[d=d#Z\	 d>	 	 	 	 	 d?d$Z]d@dAd%Z^	 dB	 	 	 	 	 dCd&Z_dddd'd(	 	 	 	 	 	 	 	 	 	 	 	 	 dDd)Z`dd*	 	 	 	 	 	 	 dEd+ZadFd,ZbdGd-Zci e( eW       e2 eSd.d      e3 eSd/d      e4 eSd0d      e5 eSdd      e6 eSd1d      e= eSd.d'      e> eSd/d'      e? eSd0d'      e@ eSdd'      eA eSd1d'      e< e[       e* e\       e: eX       e' eY       e8 eb       e9 ec       Zdd2eUd3<   d'd*	 	 	 	 	 	 	 dHd4Zey)Iz0Strategies for generating various forms of data.    )annotationsN)Mapping)datetime	timedeltatimezone)TYPE_CHECKINGAnyLiteral)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BinaryBooleanCategoricalDateDatetimeDecimalDurationEnumField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   
   )          @      )TFz*dict[bool, dict[int, SearchStrategy[int]]]_INTEGER_STRATEGIESrJ   T)signedc                   t         |   |    S )*Create a strategy for generating integers.)rL   )	bit_widthrM   s     g/var/www/html/ai-service/venv/lib/python3.12/site-packages/polars/testing/parametric/strategies/data.pyintegersrR   b   s     v&y11    	allow_nanallow_infinityc               2    t        j                  | ||      S )rO   )widthrU   rV   )stfloats)rP   rU   rV   s      rQ   rZ   rZ   i   s     999^ rS   c                 *    t        j                         S )z*Create a strategy for generating booleans.)rY   booleans rS   rQ   r\   r\   u   s    ;;=rS   c                 b    t        j                  dddg      } t        j                  | d      S )z/Create a strategy for generating string values.  CsCc)max_codepointexclude_categoriesrG   )alphabetmax_size)rY   
characterstext)rd   s    rQ   stringsrh   z   s'    }}4T4LQH77Hq11rS   c                 *    t        j                         S )z'Create a strategy for generating bytes.)rY   binaryr]   rS   rQ   rj   rj      s    99;rS   c                l    t        |       D cg c]  }d| 	 }}t        j                  |      S c c}w )z
    Create a strategy for generating category strings.

    Parameters
    ----------
    n_categories
        The number of categories.
    c)rangerY   sampled_from)n_categoriesi
categoriess      rQ   rq   rq      s6     $)#67aAaS'7J7??:&& 8s   1c                 *    t        j                         S )z0Create a strategy for generating `time` objects.)rY   timesr]   rS   rQ   rs   rs          88:rS   c                 *    t        j                         S )z0Create a strategy for generating `date` objects.)rY   datesr]   rS   rQ   rv   rv      rt   rS   c                   | dv r!t         j                  }t         j                  }nM| dk(  r8t        t	        t
        dz  dz         z   }t        t	        t        dz        z   }nd| }t        |      |t        j                  ||      S t        |      }| dk(  r|t	        d      z  }|t	        d      z  }t        j                  ||t        j                  |      d	      j                  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.
    )usmsnsr_      microsecondsinvalid time unit: )daysF)	min_value	max_value	timezonesallow_imaginaryc                `    | j                  t        j                        j                  d       S )N)tzinfo)
astimezoner   utcreplace)dts    rQ   <lambda>zdatetimes.<locals>.<lambda>   s!    R]]8<<0888E rS   )r   minmaxr   r   r   r   r   rY   	datetimesr   justmap)	time_unit	time_zoner   r   msgtime_zone_infos         rQ   r   r      s     L LL	LL		d	I7d?Q3FGG	I7d?CC	#I=1c""||Iy11i(N DYA&&	YA&&	 <<''.)	
 
c
EFGrS   c                ~   | dk(  r3t        j                  t        t              t        t                    S | dk(  r9t        j                  t        t        dz        t        t        dz              S | dk(  r3t        j                  t        t              t        t                    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.
    rx   r|   )r   r   rz   r_   ry   r~   )rY   
timedeltasr   r   r   r   )r   r   s     rQ   	durationsr      s     D}}W5W5
 	
 
d	}}W_=W_=
 	
 
d	 }}W5W5
 	

 $I=1c""rS   c                    | d} t        j                  |       }|j                  d| |z
         }|j                  |      }|j	                  |      }t        j                  ||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.
    &   )precz1E+F)r   r   rU   rV   places)decimalContextcreate_decimal
next_minuscopy_negaterY   decimals)	precisionscalerl   exclusive_limitr   r   s         rQ   r   r      sv     	Y'A&&Y->,?'@AO_-Ii(I;; rS   Fselect_frommin_sizere   uniquec                   ||dk(  rt         n|dz  }|&| j                         st        j                  |      }nt	        | f||||d|}t        j
                  ||||rt              S 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   re   	unique_by)_DEFAULT_LIST_LEN_LIMIT	is_nestedrY   rn   datalistsr9   )inner_dtyper   r   re   r   kwargsinner_strategys          rQ   r   r     s    N .6!m*A{'<'<'>5
#
 
 88%8	  ,0	 rS   )
allow_nullc          	     L   t        | t              r,| j                         D cg c]  \  }}t        ||       } }}| D ci c]%  }|j                  t        |j                  fd|i|' }}|rt        j                  i |      S t        j                  |      S c c}}w c c}w )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.
    r   )optional)	
isinstancer   itemsr&   namer   dtyperY   fixed_dictionaries)fieldsr   r   r   r   fstratss          rQ   structsr   C  s    ( &'"8>Gu%e$GGNTUaffd177DzDVDDUFU$$R&99$$V,, HUs   B*B!c                 *    t        j                         S )z-Create a strategy for generating null values.)rY   noner]   rS   rQ   nullsr   b  s    779rS   c                 4    t        j                  t              S )z3Create a strategy for generating arbitrary objects.)rY   buildsobjectr]   rS   rQ   objectsr   g  s    99VrS   rG   rH   rI   rK   z(dict[DataTypeClass, SearchStrategy[Any]]_STATIC_STRATEGIESc                  t         j                  | j                               x}|}n| t        k(  r0t	        d|j                  dd      |j                  dd            }nY| t        k(  r0t	        d|j                  dd      |j                  dd            }n | t        k(  r)t        t        | dd      xs d	t        | d
d            }n| t        k(  rt        t        | dd      xs d	      }n| t        k(  r"t        |j                  dt                    }n| t        k(  rt!        | t              rM| j                  x}j#                         rt%               }n\t'        j(                  |j+                               }n7t        |j                  dt,                    }n| t.        k(  r#t1        t        | dd      t        | dd            }n| t2        k(  r(t        | dd      xs
 t5               }t7        |fd|i|}n| t8        k(  rct        | dd      xs
 t5               }t        | dt:              }|j=                         D ci c]  \  }}|dvs|| }}}t7        |f|||d|}nL| t>        k(  r3t        | dd      xs tA        dt5                     g}	tC        |	fd|i|}nd|  }
tE        |
      |rt%               |z  }|S c c}}w )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`.
    NrI   rU   TrV   rT   rJ   r   rx   r   )r   r   )r   ro   )ro   r   r   r   innerr   size)r   re   )r   re   r   r   f0zunsupported data type: )#r   get	base_typer'   rZ   popr(   r"   r   getattrr$   r   r    rq   _DEFAULT_N_CATEGORIESr%   r   is_emptyr   rY   rn   to_listr;   r#   r   r.   r/   r   r   r:   r   r2   r&   r   r   )r   r   r   strategycatsr   r   kvr   r   s              rQ   r   r     s     '**5??+<==J	'	jjd3!::&6=

 
'	jjd3!::&6=

 
(	e[$7?4e[$7
 
(	wuk4'H'PDQ	+	N4IJ
 
$eT"(((224 7??4<<>:!#ZZ8VWH 
'	E;-wugq/I
 
$w-7@:@@	%w-7uf&@A#)<<>W41aQ>V5V!Q$WW
!	

 
 
&$/HE$4G3H6CjCFC'w/c""7X%O% Xs   
KK)rJ   )rP   zLiteral[8, 16, 32, 64, 128]rM   boolreturnzSearchStrategy[int])rP   zLiteral[32, 64]rU   r   rV   r   r   zSearchStrategy[float])r   zSearchStrategy[bool])r   SearchStrategy[str])r   zSearchStrategy[bytes])ro   intr   r   )r   zSearchStrategy[time])r   zSearchStrategy[date])rx   N)r   rB   r   z
str | Noner   zSearchStrategy[datetime])rx   )r   rB   r   zSearchStrategy[timedelta])r   r   )r   
int | Noner   r   r   zSearchStrategy[decimal.Decimal])r   rC   r   zSequence[Any] | Noner   r   re   r   r   r   r   r	   r   zSearchStrategy[list[Any]])r   zSequence[Field] | SchemaDictr   r   r   r	   r   zSearchStrategy[dict[str, Any]])r   zSearchStrategy[None])r   zSearchStrategy[object])r   r@   r   r   r   r	   r   zSearchStrategy[Any])f__doc__
__future__r   r   collections.abcr   r   r   r   typingr   r	   r
   zoneinfor   hypothesis.strategies
strategiesrY   hypothesis.errorsr   polars._utils.constantsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   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   +polars.testing.parametric.strategies._utilsr9   *polars.testing.parametric.strategies.dtyper:   r;   r<   r=   r>   r?   polars._typingr@   rA   rB   rC   rD   r   r   rR   rL   __annotations__rZ   r\   rh   rj   rq   rs   rv   r   r   r   r   r   r   r   r   r   r]   rS   rQ   <module>r      s-   6 "  # 2 2 . .  " -    $       < A
 (#4CC8   2;;vv&BKK)BKK)BKK)R[[8, 2;;q&!BKK7#BKK7#BKK7#R[[H%C ? & .02CG2*2<@22 "$	 			 	 		
 	
2
 $9 
'
 9='G'G+5'G'GT#B ./'*$D )-;; &; 	;
 ; ; ; ;B -(- - 	-
 $->
@XZ@(1T
"@ 
8Bt$@ 
8Bt$	@
 
8Bt$@ HS&@ 
8Ae$@ HR&@ HR&@ HR&@ Xc%(@ 	%'@ 	%'@ GI@ FH@  	%'!@" GI#@ < , 27OO*.OBEOOrS   