§
    qŠtjRN  ã                   ó4  — d dl mZ d dlZd dlZd dlmZmZ d dl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mZ 	 d'd„Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z d„ Z!ej"         #                    deeeg¦  «        d„ ¦   «         Z$d„ Z%d„ Z&ej"         #                    deeg¦  «        d„ ¦   «         Z'ej"         #                    dddg¦  «        d„ ¦   «         Z(ej"         #                    dddg¦  «        d„ ¦   «         Z)d„ Z*d„ Z+d„ Z,d „ Z-d!„ Z.d"„ Z/d#„ Z0d$„ Z1d%„ Z2d&„ Z3dS )(é    )ÚpartialN)ÚCallbackSupportMixinÚwith_callbacks)ÚCallbackContextÚ_from_reconstruction_attributesÚget_context_path)ÚMaxIterEstimatorÚMetaEstimatorÚNoCallbackEstimatorÚNoSubtaskEstimatorÚNotRequiredKwargsCallbackÚNotValidHookCallbackÚParentFitEstimatorÚRecordingAutoPropagatedCallbackÚRecordingCallbackÚStopFitCallbackÚThirdPartyEstimatorÚfitTc                 ó2   — t          j        | ||||¦  «        S )zÅHelper function to create a callback context with default values.

    To be used instead of estimator._init_callback_context in tests that only check
    the context tree (without callbacks).
    )r   Ú_from_estimator)Ú	estimatorÚ	task_nameÚtask_idÚmax_subtasksÚsequential_subtaskss        új/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/callback/tests/test_callback_context.pyÚ_make_callback_ctxr      s%   € õ Ô*Ø�9˜g |Ð5Hñô ð ó    c                  óÚ  — t          ¦   «         } t          ¦   «         }t          ¦   «         }t          |¦  «        }|                     | |¦  «         t          |d¦  «        rJ ‚t          |¦  «        }|                     |¦  «        5  t          |d¦  «        sJ ‚| |j        vsJ ‚||j        v sJ ‚	 ddd¦  «         n# 1 swxY w Y   t          |d¦  «        rJ ‚t          |d¦  «        rJ ‚dS )z9Check that only auto-propagated callbacks are propagated.Ú_skl_callbacksÚ_parent_callback_ctxN)	r   r   r	   r
   Úset_callbacksÚhasattrr   Úpropagate_callback_contextr    )Únot_propagated_callbackÚpropagated_callbackr   ÚmetaestimatorÚcallback_ctxs        r   Ú.test_propagate_callback_context_autopropagatedr)   +   sO  € å/Ñ1Ô1ÐÝ9Ñ;Ô;Ðå Ñ"Ô"€IÝ! )Ñ,Ô,€MØ×ÒÐ 7Ð9LÑMÔMÐMå�yÐ"2Ñ3Ô3Ð3Ð3Ð3å% mÑ4Ô4€LØ	×	0Ò	0°Ñ	;Ô	;ð ?ð ?Ý�yÐ"8Ñ9Ô9Ð9Ð9Ð9Ø&¨iÔ.FÐFÐFÐFÐFØ" iÔ&>Ð>Ð>Ð>Ð>Ð>ð?ð ?ð ?ñ ?ô ?ð ?ð ?ð ?ð ?ð ?ð ?øøøð ?ð ?ð ?ð ?õ
 �yÐ"2Ñ3Ô3Ð3Ð3Ð3Ý�yÐ"8Ñ9Ô9Ð9Ð9Ð9Ð9Ð9s   Â)B<Â<C ÃC c                  óî  — t          ¦   «         } t          ¦   «                              | ¦  «        }t          ¦   «         }t	          |¦  «        }|                     |¦  «         |j        | gk    sJ ‚t          |¦  «        }|                     |¦  «        5  t          |d¦  «        sJ ‚| |j        v sJ ‚||j        v sJ ‚	 ddd¦  «         n# 1 swxY w Y   |j        | gk    sJ ‚t          |d¦  «        rJ ‚dS )z9Check that only propagated callbacks are removed on exit.r!   N)	r   r	   r"   r   r
   r    r   r$   r#   )Úest_callbackr   Úmeta_est_callbackr'   r(   s        r   Ú(test_propagate_callback_context_clean_upr-   @   sW  € å$Ñ&Ô&€LÝ Ñ"Ô"×0Ò0°Ñ>Ô>€Iå7Ñ9Ô9ÐÝ! )Ñ,Ô,€MØ×ÒÐ 1Ñ2Ô2Ð2àÔ#¨ ~Ò5Ð5Ð5Ð5å% mÑ4Ô4€LØ	×	0Ò	0°Ñ	;Ô	;ð =ð =Ý�yÐ"8Ñ9Ô9Ð9Ð9Ð9Ø˜yÔ7Ð7Ð7Ð7Ð7Ø  IÔ$<Ð<Ð<Ð<Ð<Ð<ð=ð =ð =ñ =ô =ð =ð =ð =ð =ð =ð =øøøð =ð =ð =ð =ð
 Ô#¨ ~Ò5Ð5Ð5Ð5Ý�yÐ"8Ñ9Ô9Ð9Ð9Ð9Ð9Ð9s   Â)C
Ã
CÃCc                  óê  — t          ¦   «         } t          | ¦  «        }t          |¦  «        }t          |j        ¦  «        dk    sJ ‚|                     | ¦  «        5  t          | d¦  «        sJ ‚t          |d¦  «        rJ ‚t          | d¦  «        rJ ‚	 ddd¦  «         n# 1 swxY w Y   t          | d¦  «        rJ ‚t          | d¦  «        rJ ‚t          |d¦  «        rJ ‚t          |d¦  «        rJ ‚dS )z<Check that no callback is propagated if there's no callback.r   r!   r    N)r	   r
   r   ÚlenÚ
_callbacksr$   r#   )r   r'   r(   s      r   Ú+test_propagate_callback_context_no_callbackr1   U   sX  € å Ñ"Ô"€IÝ! )Ñ,Ô,€Må% mÑ4Ô4€LÝˆ|Ô&Ñ'Ô'¨1Ò,Ð,Ð,Ð,à	×	0Ò	0°Ñ	;Ô	;ð 8ð 8Ý�yÐ"8Ñ9Ô9Ð9Ð9Ð9Ý˜=Ð*:Ñ;Ô;Ð;Ð;Ð;Ý˜9Ð&6Ñ7Ô7Ð7Ð7Ð7Ð7ð8ð 8ð 8ñ 8ô 8ð 8ð 8ð 8ð 8ð 8ð 8øøøð 8ð 8ð 8ð 8õ
 �yÐ"2Ñ3Ô3Ð3Ð3Ð3Ý�yÐ"8Ñ9Ô9Ð9Ð9Ð9Ý�}Ð&6Ñ7Ô7Ð7Ð7Ð7Ý�}Ð&<Ñ=Ô=Ð=Ð=Ð=Ð=Ð=s   Á7B Â B$Â'B$c                  ó  — t          ¦   «         } |                      t          ¦   «         ¦  «         t          | ¬¦  «        }d}t	          j        t          |¬¦  «        5  |                     dd¬¦  «         ddd¦  «         dS # 1 swxY w Y   dS )zrCheck that it's not possible to set an auto-propagated callback on the
    sub-estimator of a meta-estimator.
    ©r   zJsub-estimator .*of a meta-estimator .*can't have auto-propagated callbacks©ÚmatchN)ÚXÚy)r	   r"   r   r
   ÚpytestÚraisesÚ	TypeErrorr   )r   Úmeta_estimatorr5   s      r   Útest_auto_propagated_callbacksr<   h   sÙ   € õ !Ñ"Ô"€IØ×ÒÕ;Ñ=Ô=Ñ>Ô>Ð>Ý"¨YÐ7Ñ7Ô7€Nð 	Vð 
õ 
Œ•y¨Ð	.Ñ	.Ô	.ð +ð +Ø×Ò˜T TÐÑ*Ô*Ð*ð+ð +ð +ñ +ô +ð +ð +ð +ð +ð +ð +ð +øøøð +ð +ð +ð +ð +ð +s   ÁBÂBÂ	Bc                 óê   — t          ¦   «         }t          || d¬¦  «        }t          | ¦  «        D ]B}|                     d||¬¦  «        }t          |¦  «        D ]}|                     d¬¦  «        }ŒŒC|S )zGHelper function to create a tree of tasks with a context for each task.F©r   r   ú
child task)r   r   r   zgrandchild task©r   )r	   r   ÚrangeÚ
subcontext)Ú
n_childrenÚn_grandchildrenr   ÚrootÚiÚchildÚjÚ
grandchilds           r   Ú_make_task_treerJ   w   s¥   € å Ñ"Ô"€IÝØ 
Àðñ ô €Dõ �:ÑÔð Gð GˆØ—’Ø"ØØ(ð  ñ 
ô 
ˆõ �Ñ'Ô'ð 	Gð 	GˆAØ×)Ò)Ð4EÐ)ÑFÔFˆJˆJð	Gð €Kr   c                  ó„  — t          dd¬¦  «        } | j        �J ‚t          t          | ¦  «        ¦  «        dk    sJ ‚t          | j        ¦  «        dk    sJ ‚| j                             ¦   «         D ]¬}|j        | u sJ ‚t          t          |¦  «        ¦  «        dk    sJ ‚t          |j        ¦  «        dk    sJ ‚|j                             ¦   «         D ]I}|j        |u sJ ‚t          t          |¦  «        ¦  «        dk    sJ ‚t          |j        ¦  «        dk    sJ ‚ŒJŒ­| D ]!}t          |j        ¦  «        |j        k    sJ ‚Œ"t          j        t          j	        g d¢¦  «        ¦  «        }t          d	„ | D ¦   «         ¦  «        }||k    sJ ‚t          d
„ | D ¦   «         ¦  «        sJ ‚t          d„ | D ¦   «         ¦  «        sJ ‚dS )z,Check that the task tree is correctly built.é   é   )rC   rD   Né   é   r   )rN   rL   rM   c              3   ó   K  — | ]}d V — ŒdS )rN   N© )Ú.0Ú_s     r   ú	<genexpr>z!test_task_tree.<locals>.<genexpr>£   s"   è è € Ð)Ð)˜q˜Ð)Ð)Ð)Ð)Ð)Ð)r   c              3   ó(   K  — | ]}|j         d u V — Œd S ©N)Úsource_estimator_name©rR   Únodes     r   rT   z!test_task_tree.<locals>.<genexpr>§   s*   è è € ÐCÐC°dˆtÔ)¨TÐ1ÐCÐCÐCÐCÐCÐCr   c              3   ó(   K  — | ]}|j         d u V — Œd S rV   )Úsource_task_namerX   s     r   rT   z!test_task_tree.<locals>.<genexpr>¨   s*   è è € Ð>Ð>°ˆtÔ$¨Ð,Ð>Ð>Ð>Ð>Ð>Ð>r   )rJ   Úparentr/   r   Ú_children_mapÚvaluesr   ÚnpÚsumÚcumprodÚall)rE   rG   rI   rY   Úexpected_n_nodesÚactual_n_nodess         r   Útest_task_treere   ‹   s  € å a¸Ð;Ñ;Ô;€DàŒ;ÐÐÐÝÕ Ñ%Ô%Ñ&Ô&¨!Ò+Ð+Ð+Ð+ÝˆtÔ!Ñ"Ô" aÒ'Ð'Ð'Ð'àÔ#×*Ò*Ñ,Ô,ð 6ð 6ˆØŒ|˜tÐ#Ð#Ð#Ð#ÝÕ# EÑ*Ô*Ñ+Ô+¨qÒ0Ð0Ð0Ð0Ý�5Ô&Ñ'Ô'¨1Ò,Ð,Ð,Ð,àÔ-×4Ò4Ñ6Ô6ð 	6ð 	6ˆJØÔ$¨Ð-Ð-Ð-Ð-ÝÕ'¨
Ñ3Ô3Ñ4Ô4¸Ò9Ð9Ð9Ð9Ý�zÔ/Ñ0Ô0°AÒ5Ð5Ð5Ð5Ð5ð	6ð ð <ð <ˆÝ�4Ô%Ñ&Ô&¨$Ô*;Ò;Ð;Ð;Ð;Ð;õ ”v�bœj¨¨¨Ñ3Ô3Ñ4Ô4ÐÝÐ)Ð) DÐ)Ñ)Ô)Ñ)Ô)€NØÐ-Ò-Ð-Ð-Ð-õ ÐCÐC¸dÐCÑCÔCÑCÔCÐCÐCÐCÝÐ>Ð>¸Ð>Ñ>Ô>Ñ>Ô>Ð>Ð>Ð>Ð>Ð>r   c                  óÒ  — t          ¦   «         } t          | dd¬¦  «        }t          | dd¬¦  «        }|                     |¦  «         |j        dk    sJ ‚t	          |j        ¦  «        dk    sJ ‚|j        dk    sJ ‚t          | dd¬¦  «        }t          j        t          d¬	¦  «        5  |                     |¦  «         d
d
d
¦  «         n# 1 swxY w Y   d|_        |                     |¦  «         t	          |j        ¦  «        dk    sJ ‚t          | dd¬¦  «        }t          j        t          d¬	¦  «        5  |                     |¦  «         d
d
d
¦  «         d
S # 1 swxY w Y   d
S )z)Sanity check for the `_add_child` method.rO   Fr>   r?   r   ©r   r   rN   z6Callback context .* already has a child with task_id=0r4   Nz$Cannot add child to callback context)
r	   r   Ú
_add_childr   r/   r]   r   r8   r9   Ú
ValueError)r   rE   Úfirst_childÚsecond_childÚthird_childs        r   Útest_add_childrm   «   s  € å Ñ"Ô"€IÝ˜i°aÈUÐSÑSÔS€DÝ$ Y¸,ÐPQÐRÑRÔR€Kà‡O‚O�KÑ Ô Ð ØÔ Ò!Ð!Ð!Ð!ÝˆtÔ!Ñ"Ô" aÒ'Ð'Ð'Ð'ØÔ !Ò#Ð#Ð#Ð#õ & i¸<ÐQRÐSÑSÔS€LÝ	ŒÝÐSð
ñ 
ô 
ð &ð &ð 	�Š˜Ñ%Ô%Ð%ð&ð &ð &ñ &ô &ð &ð &ð &ð &ð &ð &øøøð &ð &ð &ð &ð
 €LÔØ‡O‚O�LÑ!Ô!Ð!ÝˆtÔ!Ñ"Ô" aÒ'Ð'Ð'Ð'õ % Y¸,ÐPQÐRÑRÔR€Kå	Œ•zÐ)PÐ	QÑ	QÔ	Qð %ð %Ø�Š˜Ñ$Ô$Ð$ð%ð %ð %ñ %ô %ð %ð %ð %ð %ð %ð %ð %øøøð %ð %ð %ð %ð %ð %s$   Â)CÃCÃCÄ9EÅE Å#E c                  ó  — t          ¦   «         } t          | ¦  «        }t          |d¬¦  «        }|                     ddd¬¦  «        }t          | dd¬	¦  «        }|                     |¦  «         |j        |u sJ ‚|j        |j        k    sJ ‚||j                             ¦   «         vsJ ‚||j                             ¦   «         v sJ ‚|j	        dk    sJ ‚|j
        rJ ‚|j        |j        k    sJ ‚|j        |j        k    sJ ‚dS )
z*Sanity check for the `_merge_with` method.N©r   rG   r   T)r   r   r   rO   Fr>   )r	   r
   r   rB   Ú_merge_withr\   r   r]   r^   r   r   r[   r   rW   Úestimator_name)r   r;   Ú
outer_rootÚouter_childÚ
inner_roots        r   Útest_merge_withru   È   sH  € å Ñ"Ô"€IÝ" 9Ñ-Ô-€NÝ# NÀÐFÑFÔF€Jð ×'Ò'Ø¨¸tð (ñ ô €Kõ $Ø °uðñ ô €Jð ×Ò˜;Ñ'Ô'Ð'àÔ 
Ð*Ð*Ð*Ð*ØÔ Ô!4Ò4Ð4Ð4Ð4Ø˜jÔ6×=Ò=Ñ?Ô?Ð?Ð?Ð?Ð?Ø˜Ô1×8Ò8Ñ:Ô:Ð:Ð:Ð:Ð:ð Ô" aÒ'Ð'Ð'Ð'ØÔ-Ð-Ð-Ð-ð Ô&¨+Ô*?Ò?Ð?Ð?Ð?ØÔ+¨{Ô/IÒIÐIÐIÐIÐIÐIr   c                  ó>  — t          ¦   «         } t          | ¦  «        }t          | ¦  «        }t          |d¬¦  «        }|                     d¬¦  «         t	          j        t          d¬¦  «        5  |                     |¦  «         ddd¦  «         dS # 1 swxY w Y   dS )z8Check that merging with a non-leaf node raises an error.Nro   rG   r@   zCannot merge callback contextr4   )r	   r   r
   rB   r8   r9   ri   rp   )r   rt   r;   rr   s       r   Útest_merge_with_error_not_leafrw   è   sà   € å Ñ"Ô"€IÝ# IÑ.Ô.€Jå" 9Ñ-Ô-€NÝ# NÀÐFÑFÔF€Jð ×Ò GÐÑ,Ô,Ð,å	Œ•zÐ)IÐ	JÑ	JÔ	Jð +ð +Ø×Ò˜zÑ*Ô*Ð*ð+ð +ð +ñ +ô +ð +ð +ð +ð +ð +ð +ð +øøøð +ð +ð +ð +ð +ð +s   Á/BÂBÂBÚestimator_classc                 ób   —  | ¦   «                               ¦   «         }t          |d¦  «        rJ ‚dS )zBCheck that the _callback_fit_ctx attribute gets removed after fit.Ú_callback_fit_ctxN)r   r#   )rx   r   s     r   Ú#test_callback_ctx_removed_after_fitr{   ÷   s:   € ð
  �Ñ!Ô!×%Ò%Ñ'Ô'€IÝ�yÐ"5Ñ6Ô6Ð6Ð6Ð6Ð6Ð6r   c                  ó  — t          ¦   «         } t          | ¦  «        }|                     t          ¦   «         ¦  «         t	          j        t          d¬¦  «        5  |                     ¦   «          ddd¦  «         dS # 1 swxY w Y   dS )zßCheck that meta estimators can have sub estimators without callback support.

    No error is raised when the sub-estimator does not support callbacks. If callbacks
    would be propagated, a warning is raised instead.
    ú=The estimator NoCallbackEstimator does not support callbacks.r4   N)r   r
   r"   r   r8   ÚwarnsÚUserWarningr   )r   r;   s     r   Ú(test_inner_estimator_no_callback_supportr€      sÌ   € õ $Ñ%Ô%€IÝ" 9Ñ-Ô-€NØ× Ò Õ!@Ñ!BÔ!BÑCÔCÐCå	ŒÝØMð
ñ 
ô 
ð ð ð 	×ÒÑÔÐð	ð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð s   ÁA<Á<B ÂB c                  óŒ   — t          ¦   «         } |                      t          ¦   «         ¦  «         |                      ¦   «          dS )zÜCheck that callback support works for an estimator without subtasks.

    This test is about verifying that an estimator that does not call its callback
    context's `call_on_fit_task_end` does not cause a problem.
    N)r   r"   r   r   r3   s    r   Útest_estimator_without_subtaskr‚     s;   € õ #Ñ$Ô$€IØ×ÒÕ-Ñ/Ô/Ñ0Ô0Ð0Ø‡M‚M�O„O€O€O€Or   ÚCallbackc                 ól  — d} | ¦   «         }t          |¬¦  «                             |¦  «                             ¦   «          |                     d¦  «        dk    sJ ‚|                     d¦  «        d|z   k    sJ ‚|                     d¦  «        d|z   k    sJ ‚|                     d¦  «        dk    sJ ‚dS )	z©Check the number of callback hook calls in a regular estimator.

    For a regular estimator, it does not depend whether it's an autopropagated callback
    or not.
    é
   ©Úmax_iterÚsetuprN   Úon_fit_task_beginÚon_fit_task_endÚteardownN)r	   r"   r   Úcount_hooks)rƒ   r‡   Úcallbacks      r   Útest_callback_hooks_calledrŽ     sË   € ð €HØˆx‰zŒz€HÝ˜hÐ'Ñ'Ô'×5Ò5°hÑ?Ô?×CÒCÑEÔEÐEØ×Ò Ñ(Ô(¨AÒ-Ð-Ð-Ð-à×ÒÐ 3Ñ4Ô4¸¸H¹ÒDÐDÐDÐDØ×ÒÐ 1Ñ2Ô2°a¸(±lÒBÐBÐBÐBØ×Ò 
Ñ+Ô+¨qÒ0Ð0Ð0Ð0Ð0Ð0r   Ún_jobsrN   rO   c                 óæ  — d\  }}}t          ¦   «         }t          t          |¬¦  «        ||| ¬¦  «                             |¦  «                             ¦   «          |                     d¦  «        dk    sJ ‚t          j        t          j        d|||g¦  «        ¦  «        }|                     d¦  «        |k    sJ ‚|                     d¦  «        |k    sJ ‚|                     d¦  «        dk    sJ ‚d	S )
a‰  Check the number of callback hook calls in a meta-estimator.

    For an auto-propagated callback, setup and teardown are called only once,
    by the meta-estimator. To count the number of task ends, we need to aggregate the
    number of tasks from all the levels of the global task tree (which contains the
    task tree of the meta-estimator and the task trees of each sub-estimator).
    ©rO   rL   rM   r†   ©Ún_outerÚn_innerr�   rˆ   rN   r‰   rŠ   r‹   N)	r   r
   r	   r"   r   rŒ   r_   r`   ra   )r�   r“   r”   r‡   r�   Úexpected_n_taskss         r   Ú8test_meta_estimator_autopropagated_callback_hooks_calledr–   /  s  € ð ")Ñ€GˆW�hÝ.Ñ0Ô0€HÝÝ (Ð+Ñ+Ô+ØØØð	ñ ô ÷
 ‚m�HÑÔŸcšc™eœe˜eà×Ò Ñ(Ô(¨AÒ-Ð-Ð-Ð-Ý”v�bœj¨!¨W°g¸xÐ)HÑIÔIÑJÔJÐØ×ÒÐ 3Ñ4Ô4Ð8HÒHÐHÐHÐHØ×ÒÐ 1Ñ2Ô2Ð6FÒFÐFÐFÐFØ×Ò 
Ñ+Ô+¨qÒ0Ð0Ð0Ð0Ð0Ð0r   c                 ó¸  — d\  }}}t          ¦   «         }t          |¬¦  «                             |¦  «        }t          |||| ¬¦  «                             ¦   «          ||z  }|                     d¦  «        |k    sJ ‚|                     d¦  «        |d|z   z  k    sJ ‚|                     d¦  «        |d|z   z  k    sJ ‚|                     d¦  «        |k    sJ ‚d	S )
a  Check the number of callback hook calls in a meta-estimator.

    For a non auto-propagated callback, setup and teardown are called once for
    each fit of the sub-estimator. The number of task ends is the sum of the number of
    task ends from all the sub-estimators.
    r‘   r†   r’   rˆ   r‰   rN   rŠ   r‹   N)r   r	   r"   r
   r   rŒ   )r�   r“   r”   r‡   r�   ÚestÚn_fitss          r   Ú)test_meta_estimator_callback_hooks_calledrš   I  sü   € ð ")Ñ€GˆW�hÝ Ñ"Ô"€HÝ
 HÐ
-Ñ
-Ô
-×
;Ò
;¸HÑ
EÔ
E€CÝ�#˜w°ÀÐGÑGÔG×KÒKÑMÔMÐMà�wÑ€FØ×Ò Ñ(Ô(¨FÒ2Ð2Ð2Ð2à×ÒÐ 3Ñ4Ô4¸À!ÀhÁ,Ñ8OÒOÐOÐOÐOØ×ÒÐ 1Ñ2Ô2°fÀÀHÁÑ6MÒMÐMÐMÐMØ×Ò 
Ñ+Ô+¨vÒ5Ð5Ð5Ð5Ð5Ð5r   c                  óF  — d\  } }t          ¦   «         }t          t          ¦   «         | |¬¦  «                             |¦  «        }t	          j        t          d¬¦  «        5  |                     ¦   «          ddd¦  «         n# 1 swxY w Y   |                     d¦  «        dk    sJ ‚t          j
        t          j        d| |g¦  «        ¦  «        }|                     d¦  «        |k    sJ ‚|                     d	¦  «        |k    sJ ‚|                     d
¦  «        dk    sJ ‚dS )zÈCheck the number of hook calls when the sub-estimator doesn't support callbacks.

    The number of task begins and ends is just the number of nodes in the context tree
    of the meta-estimator.
    )rO   rL   )r“   r”   r}   r4   Nrˆ   rN   r‰   rŠ   r‹   )r   r
   r   r"   r8   r~   r   r   rŒ   r_   r`   ra   )r“   r”   r�   r;   r•   s        r   Ú6test_autopropagation_to_callback_agnostic_subestimatorrœ   ^  s{  € ð Ñ€GˆWÝ.Ñ0Ô0€HÝ"ÝÑÔ w¸ðñ ô ç‚m�HÑÔð õ 
ŒÝØMð
ñ 
ô 
ð ð ð 	×ÒÑÔÐð	ð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð ×Ò Ñ(Ô(¨AÒ-Ð-Ð-Ð-Ý”v�bœj¨!¨W°gÐ)>Ñ?Ô?Ñ@Ô@ÐØ×ÒÐ 3Ñ4Ô4Ð8HÒHÐHÐHÐHØ×ÒÐ 1Ñ2Ô2Ð6FÒFÐFÐFÐFØ×Ò 
Ñ+Ô+¨qÒ0Ð0Ð0Ð0Ð0Ð0s   Á BÂBÂBc                  ó$  — t          ¦   «         } |                      t          ¦   «         ¦  «                             ¦   «         }d}t	          j        t          |¬¦  «        5  |                     | dd¬¦  «         ddd¦  «         dS # 1 swxY w Y   dS )zLCheck that a callback with invalid kwargs in its signatures raises an error.z6on_fit_task_begin .* has parameters that are not validr4   rN   rO   )r   r6   r7   N)r	   r"   r   Ú_init_callback_contextr8   r9   r:   Úcall_on_fit_task_begin)r   ÚcontextÚmsgs      r   Ú$test_hook_calling_invalid_kwargs_outr¢   y  sà   € å Ñ"Ô"€IØ×%Ò%Õ&:Ñ&<Ô&<Ñ=Ô=×TÒTÑVÔV€GØ
C€CÝ	Œ•y¨Ð	,Ñ	,Ô	,ð Fð FØ×&Ò&°¸aÀ1Ð&ÑEÔEÐEðFð Fð Fñ Fô Fð Fð Fð Fð Fð Fð Fð Føøøð Fð Fð Fð Fð Fð Fs   ÁBÂB	ÂB	c                  óx  — t          ¦   «         } |                      t          ¦   «         ¦  «                             ¦   «         }|                     | ¬¦  «        }|du sJ ‚|                      t          ¦   «         t          ¦   «         ¦  «         |                      ¦   «                              | ¬¦  «        }|du sJ ‚dS )z)Check the return value of the hook calls.r3   FTN)r	   r"   r   rž   Úcall_on_fit_task_endr   )r   r    Úresults      r   Útest_hook_calling_return_valuer¦   ‚  s¶   € å Ñ"Ô"€IØ×%Ò%Õ&7Ñ&9Ô&9Ñ:Ô:×QÒQÑSÔS€GØ×)Ò)°IÐ)Ñ>Ô>€Fà�Uˆ?ˆ?ˆ?ˆ?à×ÒÕ-Ñ/Ô/µÑ1BÔ1BÑCÔCÐCØ×-Ò-Ñ/Ô/×DÒDØð Eñ ô €Fð �Tˆ>ˆ>ˆ>ˆ>ˆ>ˆ>r   c                  ó4  ‡— dddœŠˆfd„} t          ¦   «         }t          ¦   «         }|                     |¦  «                             ¦   «         }|                     |t          | d¦  «        t          | d¦  «        ¬¦  «         ‰d         dk    sJ ‚‰d         dk    sJ ‚ddiŠ|                     t          ¦   «         t          ¦   «         ¦  «         |                     ¦   «         }|                     |t          | d¦  «        ¬¦  «         ‰d         dk    sJ ‚d	S )
z©Check lazy evaluation of kwargs.

    kwargs are not evaluated if no callback uses them.
    They are evaluated only once and passed to all callbacks that use them.
    r   )r6   Úmetadatac                 ó(   •— ‰| xx         dz  cc<   dS )NrN   rQ   )ÚkeyÚeval_countss    €r   Ú
eval_kwargz5test_hook_calling_lazy_evaluation.<locals>.eval_kwargš  s$   ø€ Ø�CÐÐÔ˜AÑÐÐÑØˆqr   r6   r¨   )r   r6   r¨   rN   )r   r6   N)r	   r   r"   rž   r¤   r   r   rŸ   )r¬   r   r�   r    r«   s       @r   Ú!test_hook_calling_lazy_evaluationr­   ’  sI  ø€ ð  qÐ)Ð)€Kðð ð ð ð õ
 !Ñ"Ô"€IÝ(Ñ*Ô*€HØ×%Ò% hÑ/Ô/×FÒFÑHÔH€GØ× Ò ØÝ
�*˜cÑ
"Ô
"Ý˜ ZÑ0Ô0ð !ñ ô ð ð
 �sÔ˜qÒ Ð Ð Ð Ø�zÔ" aÒ'Ð'Ð'Ð'ð ˜�(€KØ×ÒÕ-Ñ/Ô/Õ1BÑ1DÔ1DÑEÔEÐEØ×.Ò.Ñ0Ô0€GØ×"Ò"¨Y½'À*ÈcÑ:RÔ:RÐ"ÑSÔSÐSØ�sÔ˜qÒ Ð Ð Ð Ð Ð r   c                  ó’  — t          ¦   «         } t          ¦   «         }|                      |¦  «                             ¦   «         }|                     | d„ ¬¦  «         d|j        d         d         vsJ ‚d|j        d         d         v sJ ‚|j        d         d         d         }t          |t           ¦  «        sJ ‚|j        dk    sJ ‚dS )	zÕCheck lazy evaluation of reconstruction_attributes.

    "reconstruction_attributes" is processed by the context and used to create a
    fitted estimator that is passed to the callback as "fitted_estimator".
    c                  ó
   — ddiS )NÚn_iter_rN   rQ   rQ   r   r   ú<lambda>zMtest_hook_calling_lazy_evaluation_reconstruction_attributes.<locals>.<lambda>¼  s
   € À	È1¸~€ r   )r   Úreconstruction_attributesr²   éÿÿÿÿÚkwargsÚfitted_estimatorrN   N)r	   r   r"   rž   r¤   ÚrecordÚ
isinstancer°   )r   r�   r    rµ   s       r   Ú;test_hook_calling_lazy_evaluation_reconstruction_attributesr¸   ²  så   € õ !Ñ"Ô"€IÝ Ñ"Ô"€HØ×%Ò% hÑ/Ô/×FÒFÑHÔH€GØ× Ò ØÐ7MÐ7Mð !ñ ô ð ð '¨h¬o¸bÔ.AÀ(Ô.KÐKÐKÐKÐKØ ¤°Ô!4°XÔ!>Ð>Ð>Ð>Ð>à” rÔ*¨8Ô4Ð5GÔHÐÝÐ&Õ(8Ñ9Ô9Ð9Ð9Ð9ØÔ# qÒ(Ð(Ð(Ð(Ð(Ð(r   c                  óú   — d} t          | ¬¦  «        }t          |ddi¦  «        }t          |t           ¦  «        sJ ‚||usJ ‚|                     ¦   «         |                     ¦   «         k    sJ ‚|j        dk    sJ ‚dS )z9Test the _from_reconstruction_attributes helper function.rM   r†   r°   rO   N)r	   r   r·   Ú
get_paramsr°   )r‡   r   Úreconstructed_ests      r   Ú#test_from_reconstruction_attributesr¼   È  s—   € à€HÝ ¨(Ð3Ñ3Ô3€IÝ7¸	ÀIÈqÀ>ÑRÔRÐÝÐ'Õ)9Ñ:Ô:Ð:Ð:Ð:Ø IÐ-Ð-Ð-Ð-Ø×'Ò'Ñ)Ô)¨Y×-AÒ-AÑ-CÔ-CÒCÐCÐCÐCØÔ$¨Ò)Ð)Ð)Ð)Ð)Ð)r   c                  ó¬   — t          ¦   «         } t          | dd¬¦  «        }t          d¦  «        D ]#}|                     ¦   «         }|j        |k    sJ ‚Œ$dS )zFCheck that the task_id is automatically assigned in the correct order.rM   Tr>   N)r	   r   rA   rB   r   )r   r    rF   rB   s       r   Ú test_subcontext_task_id_orderingr¾   Ó  si   € å Ñ"Ô"€IÝ  ¸ÐPTÐUÑUÔU€Gå�1‰XŒXð 'ð 'ˆØ×'Ò'Ñ)Ô)ˆ
ØÔ! QÒ&Ð&Ð&Ð&Ð&ð'ð 'r   c                  ó’  — t          ¦   «         } t          | dd¬¦  «        }t          j        t          d¬¦  «        5  |                     dd¬¦  «         d	d	d	¦  «         n# 1 swxY w Y   t          | dd
¬¦  «        }t          j        t          d¬¦  «        5  |                     d¬¦  «         d	d	d	¦  «         d	S # 1 swxY w Y   d	S )zçCheck errors raised when task_id and sequential_subtasks are inconsistent.

    - if sequential_subtasks is True, children task_ids must be left to None
    - if sequential_subtasks is False, children task_ids must be provided
    rN   Tr>   z\task_id for MaxIterEstimator child_task must be None if sequential_subtasks is True for fit.r4   Ú
child_taskr   rg   NFzatask_id for MaxIterEstimator child_task must be provided if sequential_subtasks is False for fit.r@   )r	   r   r8   r9   ri   rB   )r   r    s     r   Ú&test_subcontext_task_id_ordering_errorrÁ   Ý  sf  € õ !Ñ"Ô"€IÝ  ¸ÐPTÐUÑUÔU€GÝ	ŒÝð3ð
ñ 
ô 
ð >ð >ð 	×Ò \¸1ÐÑ=Ô=Ð=ð>ð >ð >ñ >ô >ð >ð >ð >ð >ð >ð >øøøð >ð >ð >ð >õ ! ¸ÐPUÐVÑVÔV€GÝ	ŒÝð4ð
ñ 
ô 
ð 3ð 3ð 	×Ò \ÐÑ2Ô2Ð2ð3ð 3ð 3ñ 3ô 3ð 3ð 3ð 3ð 3ð 3ð 3ð 3øøøð 3ð 3ð 3ð 3ð 3ð 3s#   ¼A Á A$Á'A$ÂB<Â<C ÃC c                  ó†  —  G d„ dt           ¦  «        }  | ¦   «         }t          ¦   «         }|                     |¦  «         |                     ¦   «          |                     d¦  «        dk    sJ ‚|                     d¦  «        dk    sJ ‚|                     d¦  «        dk    sJ ‚|                     d¦  «        dk    sJ ‚dS )	z<Check registering a callback on a locally defined estimator.c                   ó&   — e Zd Zedd„¦   «         ZdS )ú?test_locally_defined_estimator.<locals>.LocallyDefinedEstimatorNc                 ó†   — |                       ¦   «         }|                     | ¬¦  «         |                     | ¬¦  «         | S )Nr3   )rž   rŸ   r¤   )Úselfr6   r7   r(   s       r   r   zCtest_locally_defined_estimator.<locals>.LocallyDefinedEstimator.fitý  sF   € à×6Ò6Ñ8Ô8ˆLØ×/Ò/¸$Ð/Ñ?Ô?Ð?à×-Ò-¸Ð-Ñ=Ô=Ð=ØˆKr   )NN)Ú__name__Ú
__module__Ú__qualname__r   r   rQ   r   r   ÚLocallyDefinedEstimatorrÄ   ü  s2   € € € € € Ø	ð	ð 	ð 	ñ 
Œð	ð 	ð 	r   rÊ   rˆ   rN   r‰   rŠ   r‹   N)r   r   r"   r   rŒ   )rÊ   r   r�   s      r   Útest_locally_defined_estimatorrË   ù  sí   € ðð ð ð ð Õ"6ñ ô ð ð (Ð'Ñ)Ô)€IÝ Ñ"Ô"€HØ×Ò˜HÑ%Ô%Ð%Ø‡M‚M�O„O€OØ×Ò Ñ(Ô(¨AÒ-Ð-Ð-Ð-Ø×ÒÐ 3Ñ4Ô4¸Ò9Ð9Ð9Ð9Ø×ÒÐ 1Ñ2Ô2°aÒ7Ð7Ð7Ð7Ø×Ò 
Ñ+Ô+¨qÒ0Ð0Ð0Ð0Ð0Ð0r   c                  ót   — t          ¦   «         } t          | dd¬¦  «        }d}t          |¦  «        |k    sJ ‚dS )z0Smoke test for the repr of the callback context.Úmytaské*   rg   zRCallbackContext(estimator_name='MaxIterEstimator', task_name='mytask', task_id=42)N)r	   r   Úrepr)r   r    Úexpected_reprs      r   Útest_callback_context_reprrÑ     sJ   € å Ñ"Ô"€IÝ  °hÈÐKÑKÔK€Gð	ð õ �‰=Œ=˜MÒ)Ð)Ð)Ð)Ð)Ð)r   )r   r   r   T)4Ú	functoolsr   Únumpyr_   r8   Úsklearn.callbackr   r   Ú"sklearn.callback._callback_contextr   r   r   Úsklearn.callback.tests._utilsr	   r
   r   r   r   r   r   r   r   r   r   r   r)   r-   r1   r<   rJ   re   rm   ru   rw   ÚmarkÚparametrizer{   r€   r‚   rŽ   r–   rš   rœ   r¢   r¦   r­   r¸   r¼   r¾   rÁ   rË   rÑ   rQ   r   r   ú<module>rÙ      sB  ðð Ð Ð Ð Ð Ð à Ð Ð Ð Ø €€€à AÐ AÐ AÐ AÐ AÐ AÐ AÐ Aðð ð ð ð ð ð ð ð ð ð
ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð  PTð
ð 
ð 
ð 
ð:ð :ð :ð*:ð :ð :ð*>ð >ð >ð&+ð +ð +ðð ð ð(?ð ?ð ?ð@%ð %ð %ð:Jð Jð Jð@+ð +ð +ð „×ÒØÐ(Ð*=Ð?QÐRñô ð7ð 7ñô ð7ðð ð ð"ð ð ð „×ÒØÐ0Ð2CÐDñô ð1ð 1ñô ð1ð  „×Ò˜ A q 6Ñ*Ô*ð1ð 1ñ +Ô*ð1ð2 „×Ò˜ A q 6Ñ*Ô*ð6ð 6ñ +Ô*ð6ð(1ð 1ð 1ð6Fð Fð Fðð ð ð !ð !ð !ð@)ð )ð )ð,*ð *ð *ð'ð 'ð 'ð3ð 3ð 3ð81ð 1ð 1ð,*ð *ð *ð *ð *r   