§
    qŠtjw  ã                   óR  — d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	 ddl
mZ ddlmZ d„ Zd„ Z ej        ed¬	¦  «         ej        ed
¬	¦  «        gZej                             de¦  «        d„ ¦   «         Zej                             de¦  «        d„ ¦   «         Zd„ Zd„ ZdS )zûCommon pickle round-trip tests for callbacks.

These tests guard the contract that callbacks (and estimators they are attached to)
must be picklable, and that an estimator pickled after a successful fit can be
unpickled in a fresh Python interpreter.
é    N)ÚProgressBarÚScoringMonitor)ÚMaxIterEstimator)Úmake_regressionc                  óF   — t          j        d¦  «         t          ¦   «         S )NÚrich)ÚpytestÚimportorskipr   © ó    ú`/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/callback/tests/test_pickle.pyÚ_pbr      s   € Ý
Ô˜ÑÔÐÝ‰=Œ=Ðr   c                  ó"   — t          d¬¦  «        S )NÚr2©Úscoring)r   r   r   r   Ú_smr      s   € Ý $Ð'Ñ'Ô'Ð'r   r   )Úidr   Úfactoryc                 ó  — t          ¦   «                               | ¦   «         ¦  «        }t          j        t          j        |¦  «        ¦  «        }t          |¦  «        t          |¦  «        u sJ ‚t          |j        ¦  «        dk    sJ ‚dS )zJAn estimator with the callback registered but not yet fitted is picklable.é   N)r   Úset_callbacksÚpickleÚloadsÚdumpsÚtypeÚlenÚ_skl_callbacks)r   Ú	estimatorÚrestoreds      r   Ú5test_estimator_with_callback_pickle_roundtrip_pre_fitr!   '   s{   € õ !Ñ"Ô"×0Ò0°°±´Ñ;Ô;€IÝŒ|�FœL¨Ñ3Ô3Ñ4Ô4€HÝ�‰>Œ>�T )™_œ_Ð,Ð,Ð,Ð,ÝˆxÔ&Ñ'Ô'¨1Ò,Ð,Ð,Ð,Ð,Ð,r   c                 óH  —  | ¦   «         }t          d¬¦  «                             |¦  «        }|                     ¦   «          t          j        t          j        |¦  «        ¦  «        }t          |¦  «        t          |¦  «        u sJ ‚t          |j        ¦  «        dk    sJ ‚dS )zBAn estimator with the callback registered and fitted is picklable.é   ©Úmax_iterr   N)	r   r   Úfitr   r   r   r   r   r   )r   Úcallbackr   r    s       r   Ú6test_estimator_with_callback_pickle_roundtrip_post_fitr(   0   s’   € ð ˆw‰yŒy€HÝ ¨!Ð,Ñ,Ô,×:Ò:¸8ÑDÔD€IØ‡M‚M�O„O€OÝŒ|�FœL¨Ñ3Ô3Ñ4Ô4€HÝ�‰>Œ>�T )™_œ_Ð,Ð,Ð,Ð,ÝˆxÔ&Ñ'Ô'¨1Ò,Ð,Ð,Ð,Ð,Ð,r   c                 ó®  — t          j        d¦  «         t          ddd¬¦  «        \  }}t          d¬¦  «        }t	          d¬	¦  «                             t          ¦   «         |¦  «        }|                     ||¬
¦  «         |                      ¦   «         }t          j
        d|j        ¦  «        sJ ‚t          j
        d|j        ¦  «        sJ ‚|                     d¬¦  «        }t          |¦  «        dk    sJ ‚t          j        t          j        |¦  «        ¦  «        }|                     ||¬
¦  «         |                      ¦   «         }t          j
        d|j        ¦  «        sJ ‚t          j
        d|j        ¦  «        sJ ‚|j        d                              d¬¦  «        }t          |¦  «        dk    sJ ‚|d         j        |d         j        k    sJ ‚dS )z¼An estimator with callbacks survives an in-process pickle round-trip.

    It also supports re-fitting after being unpickled and the callbacks accumulate new
    data from the re-fit.
    r   é   é   r   ©Ú	n_samplesÚ
n_featuresÚrandom_stater   r   r#   r$   ©ÚXÚyúMaxIterEstimator - fitú100%Úall©Úselectr   N)r	   r
   r   r   r   r   r   r&   Ú
readouterrÚreÚsearchÚoutÚget_logsr   r   r   r   r   Údata)	Úcapsysr1   r2   Úsmr   ÚcapturedÚoriginal_logsr    Úrestored_logss	            r   Ú1test_callbacks_refit_after_pickle_in_same_processrC   ;   s¼  € õ Ô˜ÑÔÐå R°AÀAÐFÑFÔF�D€A€qå	 Ð	%Ñ	%Ô	%€BÝ ¨!Ð,Ñ,Ô,×:Ò:½;¹=¼=È"ÑMÔM€IØ‡M‚M�A˜€MÑÔÐà× Ò Ñ"Ô"€HÝŒ9Ð.°´Ñ=Ô=Ð=Ð=Ð=ÝŒ9�W˜hœlÑ+Ô+Ð+Ð+Ð+à—K’K u�KÑ-Ô-€MÝˆ}ÑÔ Ò"Ð"Ð"Ð"åŒ|�FœL¨Ñ3Ô3Ñ4Ô4€HØ‡L‚L�1˜€LÑÔÐà× Ò Ñ"Ô"€HÝŒ9Ð.°´Ñ=Ô=Ð=Ð=Ð=ÝŒ9�W˜hœlÑ+Ô+Ð+Ð+Ð+àÔ+¨AÔ.×7Ò7¸uÐ7ÑEÔE€MÝˆ}ÑÔ Ò"Ð"Ð"Ð"Ø˜ÔÔ  M°!Ô$4Ô$9Ò9Ð9Ð9Ð9Ð9Ð9r   c                 ó´  — t          j        d¦  «         t          ddd¬¦  «        \  }}t          d¬¦  «        }t	          d¬¦  «                             t          ¦   «         |¦  «        }|                     ||¬	¦  «         |                     ¦   «         }t          j
        d
|j        ¦  «        sJ ‚t          j
        d|j        ¦  «        sJ ‚|                     d¬¦  «        }t          |¦  «        dk    sJ ‚| dz  }t          |d¦  «        5 }	t          j        ||	¦  «         ddd¦  «         n# 1 swxY w Y   t#          j        dt'          |¦  «        ›d|d         j        › d�¦  «        }
t+          j        t.          j        d|
gdd¬¦  «        }|j                             ¦   «         }t          j
        d
|¦  «        sJ ‚t          j
        d|¦  «        sJ ‚dS )z¾An estimator with callbacks survives unpickling in a fresh interpreter.

    It also supports re-fitting after being unpickled and the callbacks accumulate new
    data from the re-fit.
    r   é   r#   r   r,   r   r   r$   r0   r3   r4   r5   r6   r   zest.pklÚwbNz“
        import pickle
        from sklearn.callback import ScoringMonitor
        from sklearn.datasets import make_regression

        with open(a*  , "rb") as f:
            est = pickle.load(f)

        X, y = make_regression(n_samples=20, n_features=3, random_state=1)
        est.fit(X=X, y=y)

        restored_logs = est._skl_callbacks[1].get_logs(select="all")
        assert len(restored_logs) == 2
        assert restored_logs[0].data == z	
        z-cTéx   )Úcapture_outputÚtimeout)r	   r
   r   r   r   r   r   r&   r8   r9   r:   r;   r<   r   Úopenr   ÚdumpÚtextwrapÚdedentÚstrr=   Ú
subprocessÚrunÚsysÚ
executableÚstdoutÚdecode)Útmp_pathr>   r1   r2   r?   r   r@   rA   Úpkl_pathÚfÚload_scriptÚresultrS   s                r   Ú0test_callbacks_refit_after_load_in_fresh_processrZ   \   s$  € õ Ô˜ÑÔÐå R°AÀAÐFÑFÔF�D€A€qå	 Ð	%Ñ	%Ô	%€BÝ ¨!Ð,Ñ,Ô,×:Ò:½;¹=¼=È"ÑMÔM€IØ‡M‚M�A˜€MÑÔÐà× Ò Ñ"Ô"€HÝŒ9Ð.°´Ñ=Ô=Ð=Ð=Ð=ÝŒ9�W˜hœlÑ+Ô+Ð+Ð+Ð+à—K’K u�KÑ-Ô-€MÝˆ}ÑÔ Ò"Ð"Ð"Ð"à˜)Ñ#€HÝ	ˆh˜Ñ	Ô	ð " ÝŒ�I˜qÑ!Ô!Ð!ð"ð "ð "ñ "ô "ð "ð "ð "ð "ð "ð "øøøð "ð "ð "ð "õ ”/ð	õ
 �x‘=”=ð	ð 	ð *7°qÔ)9Ô)>ð	ð 	ð 	ñô €Kõ$ Œ^Ý	Œ˜˜{Ð+¸DÈ#ðñ ô €Fð Œ]×!Ò!Ñ#Ô#€FÝŒ9Ð.°Ñ7Ô7Ð7Ð7Ð7ÝŒ9�W˜fÑ%Ô%Ð%Ð%Ð%Ð%Ð%s   ÄD/Ä/D3Ä6D3)Ú__doc__r   r9   rO   rQ   rL   r	   Úsklearn.callbackr   r   Úsklearn.callback.tests._utilsr   Úsklearn.datasetsr   r   r   ÚparamÚCALLBACK_FACTORIESÚmarkÚparametrizer!   r(   rC   rZ   r   r   r   ú<module>rc      s^  ððð ð €€€Ø 	€	€	€	Ø Ð Ð Ð Ø 
€
€
€
Ø €€€à €€€à 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø :Ð :Ð :Ð :Ð :Ð :Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,ðð ð ð
(ð (ð (ð
 €F„L�˜Ð'Ñ'Ô'Ø€F„L�Ð)Ð*Ñ*Ô*ðÐ ð „×Ò˜Ð$6Ñ7Ô7ð-ð -ñ 8Ô7ð-ð „×Ò˜Ð$6Ñ7Ô7ð-ð -ñ 8Ô7ð-ð:ð :ð :ðB1&ð 1&ð 1&ð 1&ð 1&r   