
    Mpj#H                         S r SSKrSSKrSSKJr  SSKJr  SSKJr   " S S\	5      r
 " S S	\
5      rS
 r " S S\R                  5      rSS jrg)ztThis module contains the _EstimatorPrettyPrinter class used in
BaseEstimator.__repr__ for pretty-printing estimators    N)
get_config)BaseEstimator)is_scalar_nanc                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )KeyValTupleM   z@Dummy class for correctly rendering key-value tuples from dicts.c                     > [         TU ]  5       $ )N)super__repr__)self	__class__s    Q/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/sklearn/utils/_pprint.pyr   KeyValTuple.__repr__P   s    w!!     )__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classcell__r   s   @r   r   r   M   s    J" "r   r   c                       \ rS rSrSrSrg)KeyValTupleParamU   zEDummy class for correctly rendering key-value tuples from parameters.r   N)r   r   r   r   r   r   r   r   r   r   r   U   s    Or   r   c                 `  ^ U R                  SS9n[        R                  " U R                  5      R                  mTR                  5        VVs0 s H  u  p#X#R                  _M     snnmU4S jnUR                  5        VVs0 s H  u  pVU" XV5      (       d  M  XV_M     snn$ s  snnf s  snnf )zcReturn dict (param_name: value) of parameters that were given to
estimator with non-default values.Fdeepc                 (  > U T;  a  gTU    [         R                  :X  a  g[        U[        5      (       a  UR                  TU    R                  :w  a  g[        U5      [        TU    5      :w  a$  [        TU    5      (       a  [        U5      (       d  gg)NTF)inspect_empty
isinstancer   r   reprr   )kvinit_paramss     r   has_changed$_changed_params.<locals>.has_changedc   sz    Kq>W^^+a''AKK;q>;S;S,S7d;q>**+a.))mA.>.>r   )
get_paramsr!   	signature__init__
parametersitemsdefault)	estimatorparamsnameparamr(   r%   r&   r'   s          @r   _changed_paramsr4   [   s     !!u!-F##I$6$67BBK:E:K:K:MN:M;44&:MNK $\\^A^TQ{1/@DAD^AA# O" Bs   B$B*B*c                      ^  \ rS rSrSr    SSSSS.U 4S jjjrS rS	 rS
 rS r	S r
S rS r\R                  R                  R!                  5       r\\\R$                  '   \\\R$                  '   SrU =r$ )_EstimatorPrettyPrinteru   at	  Pretty Printer class for estimator objects.

This extends the pprint.PrettyPrinter class, because:
- we need estimators to be printed with their parameters, e.g.
  Estimator(param1=value1, ...) which is not supported by default.
- the 'compact' parameter of PrettyPrinter is ignored for dicts, which
  may lead to very long representations that we want to avoid.

Quick overview of pprint.PrettyPrinter (see also
https://stackoverflow.com/questions/49565047/pprint-with-hex-numbers):

- the entry point is the _format() method which calls format() (overridden
  here)
- format() directly calls _safe_repr() for a first try at rendering the
  object
- _safe_repr formats the whole object recursively, only calling itself,
  not caring about line length or anything
- back to _format(), if the output string is too long, _format() then calls
  the appropriate _pprint_TYPE() method (e.g. _pprint_list()) depending on
  the type of the object. This where the line length and the compact
  parameters are taken into account.
- those _pprint_TYPE() methods will internally use the format() method for
  rendering the nested objects of an object (e.g. the elements of a list)

In the end, everything has to be implemented twice: in _safe_repr and in
the custom _pprint_TYPE methods. Unfortunately PrettyPrinter is really not
straightforward to extend (especially when we want a compact output), so
the code is a bit convoluted.

This class overrides:
- format() to support the changed_only parameter
- _safe_repr to support printing of estimators (for when they fit on a
  single line)
- _format_dict_items so that dict are correctly 'compacted'
- _format_items so that ellipsis is used on long lists and tuples

When estimators cannot be printed on a single line, the builtin _format()
will call _pprint_estimator() because it was registered to do so (see
_dispatch[BaseEstimator.__repr__] = _pprint_estimator).

both _format_dict_items() and _pprint_estimator() use the
_format_params_or_dict_items() method that will format parameters and
key-value pairs respecting the compact parameter. This method needs another
subroutine _pprint_key_val_tuple() used when a parameter or a key-value
pair is too long to fit on a single line. This subroutine is called in
_format() and is registered as well in the _dispatch dict (just like
_pprint_estimator). We had to create the two classes KeyValTuple and
KeyValTupleParam for this.
NFT)compactindent_at_namen_max_elements_to_showc                   > [         TU ]  XX4US9  X`l        U R                  (       a  SU l        [	        5       S   U l        Xpl        g )N)r8      print_changed_only)r
   r,   _indent_at_name_indent_per_levelr   _changed_onlyr:   )	r   indentwidthdepthstreamr8   r9   r:   r   s	           r   r,    _EstimatorPrettyPrinter.__init__   sH     	wG-%&D"'\*>? '=#r   c                 ,    [        XX4U R                  S9$ )Nchanged_only)
_safe_reprr@   )r   objectcontext	maxlevelslevels        r   format_EstimatorPrettyPrinter.format   s    YD<N<N
 	
r   c                    UR                  UR                  R                  S-   5        U R                  (       a"  U[	        UR                  R                  5      -  nU R
                  (       a  [        U5      nOUR                  SS9nU R                  [        UR                  5       5      X#US-   XV5        UR                  S5        g )N(Fr   r<   ))writer   r   r>   lenr@   r4   r*   _format_paramssortedr.   )r   rJ   rD   rA   	allowancerK   rM   r1   s           r   _pprint_estimator)_EstimatorPrettyPrinter._pprint_estimator   s    V%%..45c&**3344F$V,F&&E&2F6<<>"FIM7	
 	Sr   c           
      &    U R                  XX4XVSS9$ )NTis_dict_format_params_or_dict_itemsr   r.   rD   rA   rW   rK   rM   s          r   _format_dict_items*_EstimatorPrettyPrinter._format_dict_items   s#    006gd 1 
 	
r   c           
      &    U R                  XX4XVSS9$ )NFr[   r]   r_   s          r   rU   &_EstimatorPrettyPrinter._format_params   s#    006ge 1 
 	
r   c                 B   UR                   nX0R                  -  nSSU-  -   n	Sn
U R                  U-
  S-   =p[        U5      n [	        U5      nSnSnU(       Gd  UU R                  :X  a	  U" S5        gUS-  nUn [	        U5      nU R                  (       a  Uu  nnU R                  UXV5      nU R                  UXV5      nU(       d  UR                  S
5      nU(       a  SOSnUU-   U-   n[        U5      S-   nUU:  a  UnU
(       a  U	n
UU:  a  UU-  nU" U
5        Sn
U" U5        M  U" U
5        U	n
U(       a  [        O[        nU R                  U" U5      X#U(       a  UOSXV5        U(       d  GM  gg! [
         a     gf = f! [
         a    S	nX-  nX-  n GNf = f)a  Format dict items or parameters respecting the compact=True
parameter. For some reason, the builtin rendering of dict items doesn't
respect compact=True and will use one line per key-value if all cannot
fit in a single line.
Dict items will be rendered as <'key': value> while params will be
rendered as <key=value>. The implementation is mostly copy/pasting from
the builtin _format_items().
This also adds ellipsis if the number of items is greater than
self.n_max_elements_to_show.
,
  r<   NFr   , ...T': =   , )rS   r?   _widthiternextStopIterationr:   _compact_reprstriprT   r   r   _format)r   rJ   rD   rA   rW   rK   rM   r\   rS   delimnldelimrB   	max_widthitnext_entlastn_itemsentr%   r&   kreprvreprmiddlerepwclass_s                             r   r^   4_EstimatorPrettyPrinter._format_params_or_dict_items   s    (((#,& KK&0144&\	BxH $555gqLGC#8
 }}1

1g5

1g5!KK,E!(cfnu,HqL19%E 'A:QJE%L E#J%LE$+[1AFLLsV$YAwE $	  		 ! #&	"#s$   E6 <F 6
FFFFc                    UR                   nX0R                  -  nU R                  S:  a  U" U R                  S-
  S-  5        SSU-  -   nSn	U R                  U-
  S-   =p[        U5      n [	        U5      nSnSnU(       d  XR                  :X  a	  U" S5        gUS-  nUn [	        U5      nU R                  (       aP  U R                  UXV5      n[        U5      S
-   nU
U:  a  Un
U	(       a  Un	U
U:  a  U
U-  n
U" U	5        Sn	U" U5        M  U" U	5        Un	U R                  UX#U(       a  UOSXV5        U(       d  M  gg! [
         a     gf = f! [
         a    S	nX-  nX-  n
 Nf = f)zFormat the items of an iterable (list, tuple...). Same as the
built-in _format_items, with support for ellipsis if the number of
elements is greater than self.n_max_elements_to_show.
r<   rf   re   rg   NFr   rh   Trl   rm   )rS   r?   rn   ro   rp   rq   r:   rr   rs   rT   ru   )r   r.   rD   rA   rW   rK   rM   rS   rv   rw   rB   rx   ry   rz   r{   r|   r}   r   r   s                      r   _format_items%_EstimatorPrettyPrinter._format_items  s   
 (((!!A%4))A-45#,& KK&0144%[	BxH 555gqLGC#8
 }}jjg5HqL19%E 'A:QJE%L E#J%LELLf4iQW7 $	  		 ! #&	"#s$   ,E  "E  
EEE'&E'c                 "   Uu  pxU R                  XuU5      n	[        U[        5      (       a  U	R                  S5      n	Sn
OSn
UR	                  U	5        UR	                  U
5        U R                  XU[        U	5      -   [        U
5      -   XEU5        g)z=Pretty printing for key-value tuples from dict or parameters.ri   rk   rj   N)rs   r#   r   rt   rS   ru   rT   )r   rJ   rD   rA   rW   rK   rM   r%   r&   r   r   s              r   _pprint_key_val_tuple-_EstimatorPrettyPrinter._pprint_key_val_tupleJ  s}    jjU+f.//))C.CFFSVvC(3v;6	E	
r   )r@   r>   r?   r:   )r<   P   NN)r   r   r   r   r   r,   rN   rX   r`   rU   r^   r   r   pprintPrettyPrinter	_dispatchcopyr   r   r   r   r   r   s   @r   r6   r6   u   s    0h = #= =*





=~.X`
& $$..335I(9Im$$%&;Ik""#r   r6   c           	      (   [        U 5      nU[        R                  ;   a  [        U 5      SS4$ [	        USS5      n[        U[        5      (       Ga  U[        R                  L a  U (       d  g[        U 5      nU(       a  X2:  a  SSXq;   4$ Xq;   a  [        R                  " U 5      SS4$ SX'   SnSn	/ n
U
R                  nUS-  n[        n[        U R                  5       [        R                  S9nU HR  u  pU" XX#US	9u  nnnU" XX#US	9u  nnnU" U< S
U< 35        U=(       a    U=(       a    UnU(       d	  U(       d  MP  Sn	MT     X	 SSR                  U
5      -  X4$ [        U[         5      (       a  U[         R                  L d(  [        U["        5      (       a  U["        R                  L a  [        U[         5      (       a  U (       d  gSnO[%        U 5      S:X  a  SnO
U (       d  gSn[        U 5      nU(       a  X2:  a
  US-  SXq;   4$ Xq;   a  [        R                  " U 5      SS4$ SX'   SnSn	/ n
U
R                  nUS-  nU  H.  n[        UXX4S	9u  nnnU" U5        U(       d  SnU(       d  M,  Sn	M0     X	 USR                  U
5      -  X4$ [        U[&        5      (       Ga@  [        U 5      nU(       a  X2:  a  UR(                   S3SXq;   4$ Xq;   a  [        R                  " U 5      SS4$ SX'   SnSn	U(       a  [+        U 5      nOU R-                  SS9n/ n
U
R                  nUS-  n[        n[        UR                  5       [        R                  S9nU Ha  u  pU" XX#US	9u  nnnU" XX#US	9u  nnnU" UR/                  S5      < SU< 35        U=(       a    U=(       a    UnU(       d	  U(       d  M_  Sn	Mc     X	 UR(                  < SSR                  U
5      < S3X4$ [        U 5      nUU=(       a    UR1                  S5      (       + S4$ )zISame as the builtin _safe_repr, with added support for Estimator
objects.TFr   N)z{}TFz{...}r<   )keyrG   rj   z{%s}rm   )z[]TFz[%s]z(%s,))z()TFz(%s)z...z(...)r   ri   rk   rQ   rR   <)typer   _builtin_scalarsr$   getattr
issubclassdictr   id
_recursionappendrI   rV   r.   _safe_tuplejoinlisttuplerT   r   r   r4   r*   rt   
startswith)rJ   rK   rL   rM   rH   typrobjidreadable	recursive
componentsr   safereprr.   r%   r&   r~   	kreadablekrecurr   	vreadablevrecurrN   oorepr	oreadableorecurr1   r   s                                r   rI   rI   b  s    v,C
f%%%F|T5((Z&A#tdmm!3$6
+E5#333$$V,eT99	
""
v||~6+=+=>DA'/I<($E9f (0I<($E9f ue,-;I;)H 	  N		*--xBB3!t}}"431#6c4  (F[AF(F6
+E>5%*:::$$V,eT99	
""
A'17u($E9f 5M v 	  N		*--xBB#}%%6
+ll^5)5%2BBB$$V,eT99	$V,F&&E&2F
""
v||~6+=+=>DA'/I<($E9f (0I<($E9f ekk#.67;I;)H 	  NLL$))J*?@(VV
v,C0S^^C00588r   )F)r   r!   r   sklearn._configr   sklearn.baser   sklearn.utils._missingr   r   r   r   r4   r   r6   rI   r   r   r   <module>r      sU   9H   & & 0"% "	{ 	B4j<f22 j<Zl9r   