`L iXHdZddlZddlZddlmZddlmZddlmZGdd e Z Gd d e Z d Z Gd dejZddZy)ztThis module contains the _EstimatorPrettyPrinter class used in BaseEstimator.__repr__ for pretty-printing estimatorsN) get_config) BaseEstimator) is_scalar_nanc"eZdZdZfdZxZS) KeyValTuplez@Dummy class for correctly rendering key-value tuples from dicts.c t|S)N)super__repr__)self __class__s [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/utils/_pprint.pyr zKeyValTuple.__repr__Psw!!)__name__ __module__ __qualname____doc__r __classcell__rs@rr r MsJ""rr ceZdZdZy)KeyValTupleParamzEDummy class for correctly rendering key-value tuples from parameters.N)rrrrrrrrUsOrrc|jd}t|jd|j}tj|j j Dcic]\}}||jc}}fd}|j Dcic]\}}|||s||c}}Scc}}wcc}}w)zgReturn dict (param_name: value) of parameters that were given to estimator with non-default values.Fdeepdeprecated_originalc|vry|tjk(ryt|tr|j|jk7ryt |t |k7rt |r t |syy)NTF)inspect_empty isinstancerrreprr)kv init_paramss r has_changedz$_changed_params..has_changeddsq K  q>W^^ + a 'AKK;q>;S;S,S 7d;q>* * +a. )mA.>r) get_paramsgetattr__init__r signature parametersitemsdefault) estimatorparams init_funcnameparamr&r#r$r%s @r_changed_paramsr3[s ! !u ! -F **,A9CUCUVI##I.99K:E:K:K:MN;44&NK $\\^ ATQ{1a/@AqD AA#O" Bs'B5B;,B;ceZdZdZ dddddfd ZdZdZd Zd Zd Z d Z d Z e jjjZeeej"<e eej"<xZS)_EstimatorPrettyPrintera 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)compactindent_at_namen_max_elements_to_showct||||||||_|jrd|_t d|_||_y)N)r6rprint_changed_only)r r)_indent_at_name_indent_per_levelr _changed_onlyr8) r indentwidthdepthstreamr6r7r8rs rr)z _EstimatorPrettyPrinter.__init__sP vwG-   %&D "'\*>?'=#rc6t|||||jS)N changed_only) _safe_reprr=)r objectcontext maxlevelslevels rformatz_EstimatorPrettyPrinter.formats  GYD allowancerGrIr/s r_pprint_estimatorz)_EstimatorPrettyPrinter._pprint_estimators V%%..45    c&**334 4F   $V,F&&E&2F  6<<> "FFIM7E   Src 2|j||||||dS)NTis_dict_format_params_or_dict_itemsr r,rAr>rRrGrIs r_format_dict_itemsz*_EstimatorPrettyPrinter._format_dict_itemss)00 669gud1  rc 2|j||||||dS)NFrUrWrYs rrPz&_EstimatorPrettyPrinter._format_paramss)00 669gue1  rc|j}||jz }dd|zz} d} |j|z dzx} } t|} t | }d}d}|s||j k(r |dy|dz }|} t | }|jr|\}}|j|||}|j|||}|s|jd }|rd nd }||z|z}t|d z}| |kr| } | r| } | |k\r| |z} || d} |||| | } |rtnt}|j|||||r|nd|||syy#t $rYywxYw#t $rd }| |z} | |z} YwxYw)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 . 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. ,  rNFr, ...T': =r, )rNr<_widthiternext StopIterationr8_compact_reprstriprOr r_format)r rFrAr>rRrGrIrVrNdelimnldelimr? max_widthitnext_entlastn_itemsentr#r$kreprvreprmiddlerepwclass_s rrXz4_EstimatorPrettyPrinter._format_params_or_dict_itemss $(((#,& KK&0144 &\ BxH$555g qLGC #8 }}1 1gu5 1gu5!KK,E!(cfnu,HqL19%E 'A:QJE%L E#J %LE$+[1AF LLs VV$YAwPU E    ! #Y& " #s$ E 7 E EEE43E4c|j}||jz }|jdkDr||jdz dzdd|zz}d} |j|z dzx} } t|} t | } d}d}|s||j k(r |dy|dz }| } t | } |jrI|j|||}t|d z}| |kr| } | r|} | |k\r| |z} || d } |||| |} |j||||r|nd|||syy#t $rYywxYw#t $rd }| |z} | |z} YwxYw) 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. rr^r]r_NFrr`Trrd) rNr<rerfrgrhr8rirjrOrl)r r,rAr>rRrGrIrNrmrnr?rorprqrrrsrtrxrys r _format_itemsz%_EstimatorPrettyPrinter._format_itemss  $(((  ! !A % 4))A-4 5#,& KK&0144 %[ BxH$555g qLGC #8 }}jjgu5HqL19%E 'A:QJE%L E#J %LE LLff4iQQV W7    ! #Y& " #s$- D' D6' D32D36E Ec |\}}|j|||} t|tr| jd} d} nd} |j | |j | |j |||t | zt | z|||y)z=Pretty printing for key-value tuples from dict or parameters.rarcrbN)rjr!rrkrNrlrO) r rFrAr>rRrGrIr#r$rxrws r_pprint_key_val_tuplez-_EstimatorPrettyPrinter._pprint_key_val_tupleKs1jjGU+ f. /))C.CFF S V vvC(3v;6 7E r)rPNN)rrrrr)rJrSrZrPrXr|r~pprint PrettyPrinter _dispatchcopyrr r rrs@rr5r5vs0h =#=*   =~.X`  &$$..335I(9Im$$%&;Ik""#rr5c\t|}|tjvrt|ddfSt |dd}t |t r|t jur|syt|}|r ||k\rdd||vfS||vrtj|ddfSd||<d}d} g} | j} |dz }t} t|jtj} | D]E\}}| ||||| \}}}| ||||| \}}}| |d ||xr|xr|}|s|sDd} G||=d d j| z|| fSt |t r|t jus"t |t"r|t"jurt |t r|sy d}nt%|dk(rd}n|syd}t|}|r||k\r |dzd||vfS||vrtj|ddfSd||<d}d} g} | j} |dz }|D]'}t||||| \}}}| ||sd}|s&d} )||=|d j| z|| fSt |t&r-t|}|r||k\r|j(dd||vfS||vrtj|ddfSd||<d}d} |r t+|}n|j-d}g} | j} |dz }t} t|jtj} | D]T\}}| ||||| \}}}| ||||| \}}}| |j/dd||xr|xr|}|s|sSd} V||=|j(dd j| d|| fSt|}||xr|j1d dfS)zMSame as the builtin _safe_repr, with added support for Estimator objects.TFr N)z{}TFz{...}r)keyrCrbz{%s}rd)z[]TFz[%s]z(%s,))z()TFz(%s)z...z(...)rrarcrLrM<)typer_builtin_scalarsr"r( issubclassdictr id _recursionappendrErQr, _safe_tuplejoinlisttuplerOrrr3r'rk startswith)rFrGrHrIrDtyprobjidreadable recursive componentsrsafereprr,r#r$ru kreadablekrecurrv vreadablevrecurrJoorepr oreadableorecurr/rxs rrErEcsD v,C f%%%F|T5((Z&A#tdmm!3$6  )+E5G#33 3 G $$V,eT9 9  ""  v||~6+=+=> !DAq'/7Iu<( $E9f(07Iu<( $E9f ue, -;I;)H  ! EN *--xBB3!t}}"431#6 c4 (F [A F(F6  )+E>5%7*:: : G $$V,eT9 9  ""   !A'17Iu<( $E9f 5M   ! EN *--xBB#}%6  )+ll^5)5%72BB B G $$V,eT9 9 $V,F&&E&2F ""  v||~6+=+=> !DAq'/7Iu<( $E9f(07Iu<( $E9f ekk#.6 7;I;)H  ! ENLL$))J*?@(IVV v,C 0S^^C005 88r)F)rrr_configrbaser_missingrrr rr3rr5rErrrrsU9H #"%" { B6j