
    
3jA8              	           S SK r S SKrS SKJrJrJrJrJrJr  S SK	J
r
  S SKJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJrJr  \(       a  S SKJ r    " S S\ \5      r!S	r" " S
 S5      r#\$" / 5      4S jr%SS jr&S S\'4S jjr(Sr)\)4S jr*S!S\S\S\'S\+4S jjr,S\S\S\'4S jr-SS\'4S jjr.S r/S r0S r1S r2\\&4\R                  \/4\Rf                  \04\Rh                  \14\Rj                  \24/r6S"S jr7g)#    N)TYPE_CHECKINGCallableProtocolAnyUnionOptional)DeepHash)
DELTA_VIEWnumbersstringsadd_to_frozen_set	not_foundonly_numbersnp
np_float64time_to_secondscartesian_product_numpy
np_ndarraynp_array_factory,get_homogeneous_numpy_compatible_type_of_seqdict_CannotCompare
NumberType)MappingIterable)DeepDiffProtocolc            	           \ rS rSr% \\S'   \\S'   \\S'   \\   \S'   \\	   \S'   \	\S'   SS\
S	\	4S
 jjr   SS\S\S\S	\4S jjrS\S	S4S jrSrg)DistanceProtocol   hashesdeephash_parametersignore_numeric_type_changesiterable_compare_funcmath_epsiloncutoff_distance_for_pairsparentreturnc                     g N )selfitemr&   s      K/home/wildlama/miniconda3/lib/python3.13/site-packages/deepdiff/distance.py__get_item_rough_length(DistanceProtocol.__get_item_rough_length           directedreport_repetition_requiredalways_include_valuesc                     g r)   r*   )r+   r2   r3   r4   s       r-   _to_delta_dictDistanceProtocol._to_delta_dict   s     r1   r,   Nc                     g r)   r*   r+   r,   s     r-   __calculate_item_deephash*DistanceProtocol.__calculate_item_deephash!   r0   r1   r*   root)TTF)__name__
__module____qualname____firstlineno__dict__annotations__boolr   r   floatstr(_DistanceProtocol__get_item_rough_lengthr6   r   *_DistanceProtocol__calculate_item_deephash__static_attributes__r*   r1   r-   r   r      s    !!%))'11uo%#((	s 	e 	
 "/3*/			 )-	 $(		
 		# 	$ 	r1   r   zTDistance calculation can not happen once the cache is purged. Try with _cache='keep'c                   ^    \ rS rSrSS jrSSS jjrSSS\SS4S	 jr  SS
 jr  SS jr	Sr
g)DistanceMixin)   r+   r   c                 ~   [        U R                  U R                  U R                  U R                  U R
                  S9nU[        La  U$ U R                  [        :X  a  U OU R                  SS9n[        U5      nUS:X  a  gU R                  U R                  5      nU R                  U R                  5      nX4U-   -  $ )a  
Gives a numeric value for the distance of t1 and t2 based on how many operations are needed to convert
one to the other.

This is a similar concept to the Levenshtein Edit Distance but for the structured data and it is designed
to be between 0 and 1.

A distance of zero means the objects are equal and a distance of 1 is very far.

Note: The distance calculation formula is subject to change in future. Use the distance results only as a
way of comparing the distances of pairs of items with other pairs rather than an absolute distance
such as the one provided by Levenshtein edit distance.

Info: The current algorithm is based on the number of operations that are needed to convert t1 to t2 divided
by the number of items that make up t1 and t2.
max_use_log_scalelog_scale_similarity_thresholdF)r3   r   )get_numeric_types_distancet1t2r%   rP   rQ   r   viewr
   r6   _get_item_length%_DistanceMixin__get_item_rough_length)r+   	_distancer,   diff_lengtht1_lent2_lens         r-   _get_rough_distance!DistanceMixin._get_rough_distance+   s    $ /GGTWW4#A#AQUQcQc  EI  Eh  Ehi	 I%yyJ.tD4G4Gch4G4i&t,!--dgg6--dgg6vo..r1   c                    [        U S5      (       d  [        [        5      e[        R                  " U R
                  USSU R                  S9nUc=  U R                  U5        [        R                  " U R
                  USSU R                  S9nU$ )z
Get the rough length of an item.
It is used as a part of calculating the rough distance between objects.

**parameters**

item: The item to calculate the rough length for
parent: It is only used for DeepHash reporting purposes. Not really useful here.
r    N   )keydefaultextract_indexr"   )hasattrRuntimeErrorDISTANCE_CALCS_NEEDS_CACHEr	   get_keyr    r"   '_DistanceMixin__calculate_item_deephash)r+   r,   r&   lengths       r-   r.   %DistanceMixin.__get_item_rough_lengthN   s     tX&&9::!!$++4UV?C?_?_a>**40%%dkktTYZCGCcCceFr1   r,   r'   Nc                 L    [        U4U R                  SSS.U R                  D6  g )Nr=   T)r    r&   
apply_hash)r	   r    r!   r9   s     r-   r:   'DistanceMixin.__calculate_item_deephashb   s/    	
;;		

 &&	
r1   c                 >   [        5       nU R                  c  U$ U R                  nU H`  nU HW  n	 U" XH   R                  X9   R                  5      n
U
(       a  U R                  =(       d    SnOSnXSR	                  X5      '   MY     Mb     U$ ! [
         a     Mn  f = f)Ngư>r_   {}--{})r   r#   r,   r$   formatr   )r+   hashes_addedhashes_removedt1_hashtablet2_hashtable_original_typepre_calced_distancescompare_func
added_hashremoved_hashis_close_distancedistances               r-   -_precalculate_distance_by_custom_compare_func;DistanceMixin._precalculate_distance_by_custom_compare_funck   s    $w%%-''11&J .
_(4\5M5R5RT`TnTsTs(t% )#'#4#4#@#$V^)RS !/ ' $# % s   !B
BBc                    [        U[        [        U5      5         R                  [        [
        45      (       a  g [        5       nU Vs/ s H  otU   R                  PM     nnU Vs/ s H  osU   R                  PM     n	nUc$  [        U5      n
[        U	5      nU
(       a  X:X  a  U
nUc  g [        XS9n[        XS9n	[        X5      nUR                  n[        US   US   U R                  U R                  U R                  S9nSnU H(  nU H  nX   USR                  UU5      '   US-  nM!     M*     U$ s  snf s  snf )N)dtyper   r_   rN   rn   )
isinstancenextiterr,   r   listr   r   r   r   T_get_numpy_array_distancer%   rP   rQ   ro   )r+   rp   rq   rr   rs   rt   ru   kaddedremovedadded_numpy_compatible_typeremoved_numpy_compatible_typepairspairs_transposed	distancesirw   rx   s                     r-   #_precalculate_numpy_arrays_distance1DistanceMixin._precalculate_numpy_arrays_distance   sN    l4\(:#;<AAJPTCUVV$w/;<|!a%%|<1?@A?''@!*VW\*]',XY`,a)*/J/k!<! ="7A'7 77-Q!1!!4//,,+/+N+N	
	 &J .R[R^$X__Z%NOQ !/ ' $#= =@s   
D9(D>r*   )r+   r   r<   )r>   r?   r@   rA   r\   rW   r   rg   r{   r   rI   r*   r1   r-   rK   rK   )   sB    !/F(
(: 
# 
$ 
$$$,&$$&$r1   rK   c                 .   Sn[        U [        5      (       Ga  U R                  5        GH   u  p4US;   a}  [        5       nUR                  5        H]  u  pg[	        5       n[        5       n	UR                  5        H,  u  p[        U5      nX;  d  M  UR                  U5        XU
'   M.     XU'   M_     Un[        U[        5      (       a0  UR                  S5      (       d  US:X  d  US:X  d  US:X  d  US:X  a  M  [        U5      nU(       a  X;   a  M  [        X5      nU[        XN5      -  nGM     U$ [        U [        5      (       a  SnU$ [        U [        5      (       a  SnU$ [        U [        5      (       a=  U  H5  n[        U5      nU(       a  X;   a  M  [        X5      nU[        XN5      -  nM7     U$ [        U [        5      (       a  SnU$ [        U S	5      (       a7  U R                    H'  n[        U5      n[        X5      nU[        XN5      -  nM)     U$ )
z
Get the number of operations in a diff object.
It is designed mainly for the delta view output
but can be used with other dictionary types of view outputs too.
r   >   iterable_items_added_at_indexes!iterable_items_removed_at_indexes_deep_distancenew_pathold_type	old_valuer_   __dict__)r   r   itemsr   setidaddrF   
startswithr   rV   r   r   r   typerc   r   )r,   parents_idsrh   r`   subitemnew_subitempath_indexes_to_itemsused_value_idsnew_indexes_to_itemsr   vv_iditem_idparents_ids_addeds                  r-   rV   rV      s    F$   JJLLC^^#g/6}}+E%(UN+07( 0 6 6 8!!u5*..t4673	 !9
 *>& 0? & #s##)<)<@VZ]akZk,/:,=ASkGw5 1+ G&wBBF3 )Z M' 
D'	"	"$ M# 
D'	"	"  M 
D(	#	#GkGw5 1+ G&wBBF  M 
D$		 M 4$$==W+$5k$K!*7FF ) Mr1   c                 <   X:X  a  gU(       a  [        X5      nUS:  a  gU$ [        U [        5      (       d  [        U 5      n [        U[        5      (       d  [        U5      nX-   U-  nUS:X  a  U$  [        U[	        X-
  U-  5      5      $ ! [
         a    Us $ f = f)
Get the distance of 2 numbers. The output is a number between 0 to the max.
The reason is the
When max is returned means the 2 numbers are really far, and 0 means they are equal.
r   )logarithmic_distancer   rE   minabs	Exception)num1num2rO   rP   rQ   rz   divisors          r-   _get_numbers_distancer      s     |'3a<dE""T{dE""T{
 {d"G!|4dkW4566 s   2B BBreplace_inf_withc                     [         R                  " U R                  U[        S9n[         R                  " XX1S:g  [        S9nSX@U:H  '   U$ )N)shape
fill_valuer~   r   )outwherer~   )r   fullr   r   divide)abr   	max_arrayresults        r-   
_numpy_divr      s?    agg2B*UIYYqq&
KFF6NMr1   g|=c                     [         R                  " U 5      U-   n[         R                  " U5      n[         R                  " X05      nU$ r)   )r   r   logcopysign)arrayoffsetabs_plus_offset
log_valuessigned_log_valuess        r-   numpy_apply_log_keep_signr   
  s;    ffUmf,O (J J6r1   r   r   	thresholdr'   c                     [        X5      U:  $ )z
A threshold of 0.1 translates to about 10.5% difference.
A threshold of 0.5 translates to about 65% difference.
A threshold of 0.05 translates to about 5.1% difference.
)r   )r   r   r   s      r-   logarithmic_similarityr     s      %	11r1   c                 4   [        U 5      n [        U5      n[        R                  " [        R                  " [	        U 5      [
        -   5      U 5      n[        R                  " [        R                  " [	        U5      [
        -   5      U5      n[	        X#-
  5      $ r)   )rE   mathr   r   r   MATH_LOG_OFFSET)r   r   log_alog_bs       r-   r   r      se    aAaAMM$((3q6O#;<a@EMM$((3q6O#;<a@Eu}r1   rO   c                     U(       a  [        U 5      n [        U5      nX-   U-  n[        X-
  XRS9n[        R                  " [        R                  " U5      SU5      nU(       a  SXwU:  '   U$ )r   )r   r   )r   r   r   clipabsolute)r   r   rO   rP   rQ   r   r   distance_arrays           r-   r   r   *  sg     (.(.{d"GwFFWWR[[0!T:NJK(FFGr1   c                 T    [        U R                  5       UR                  5       U5      $ r)   )r   	timestampdate1date2rO   rP   rQ   s        r-   _get_datetime_distancer   A       !2EOO4EtLLr1   c                 T    [        U R                  5       UR                  5       U5      $ r)   )r   	toordinalr   s        r-   _get_date_distancer   E  r   r1   c                 T    [        U R                  5       UR                  5       U5      $ r)   )r   total_seconds)
timedelta1
timedelta2rO   rP   rQ   s        r-   _get_timedelta_distancer   I  s$     !9!9!;Z=U=U=WY]^^r1   c                 @    [        [        U 5      [        U5      U5      $ r)   )r   r   )time1time2rO   rP   rQ   s        r-   _get_time_distancer   M  s     !79OQUVVr1   c                     [          H3  u  pV[        X5      (       d  M  [        X5      (       d  M)  U" XX#U5      s  $    [        $ r)   )TYPES_TO_DIST_FUNCr   r   )r   r   rO   rP   rQ   type_funcs          r-   rR   rR   Z  s;    )d""z$'>'>D9WXX * r1   )r_   F皙?)r_   )r   )Fr   )8r   datetimetypingr   r   r   r   r   r   deepdiff.deephashr	   deepdiff.helperr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   collections.abcr   r   deepdiff.diffr   r   re   rK   	frozensetrV   r   rE   r   r   r   rD   r   r   r   r   r   r   r   date	timedeltatimer   rR   r*   r1   r-   <module>r      s<     J J &     ..+X 0 t ~$ ~$B (1} 5p<u  ,; 
2j 2Z 2E 2RV 2J : %  .MM_W
 ()./]]&'01]]&' r1   