o
    Ù­jÜ  ã                   @   s”  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mZm	Z	m
Z
mZmZ ddlZddlmZmZ er:ddlZddlZejd dksEJ dƒ‚dedB d	efd
d„Zde	deded	efdd„ZzHddlmZ ddlm Z! ddlm"Z# ddlm$Z% zddl&m'Z( W n e)y�   ddl*m'Z( Y nw zddl+m,Z- W n e)y¡   e.Z-Y nw dZ/W n& e)yË   dZ/G dd„ dƒZ!G dd„ dƒZ#G dd„ dƒZ%dZ(e.Z-e.ZY nw e 0e1¡Z2ej3d	efdd „ƒZ4ej3d	efd!d"„ƒZ5ej3d	ej6fd#d$„ƒZ7ej3d	efd%d&„ƒZ8ej3d	ej6fd'd(„ƒZ9ej3d	ej6fd)d*„ƒZ:ej3d	ej6fd+d,„ƒZ;ej3d	efd-d.„ƒZ<zddl=m>Z? dd/l=m@ZA W n e)�yA   dZ?e.ZAY nw d0ed	efd1d2„ZBd0ed	efd3d4„ZCd0ed	efd5d6„ZDd0ed	ed7 fd8d9„ZEd0ed	efd:d;„ZFd0ed	efd<d=„ZGd0ed	efd>d?„ZHd0ed	ed@ fdAdB„ZId0ed	edC fdDdE„ZJd0ed	efdFdG„ZKd0ed	efdHdI„ZLd0ed	efdJdK„ZMd0ed	efdLdM„ZNdNe
e d	efdOdP„ZOdS )Qz,For compatibility and optional dependencies.é    N)ÚTYPE_CHECKINGÚAnyÚSequenceÚ	TypeGuardÚcasté   )Ú_TÚDataTypeé   z Python 2 is no longer supported.ÚxÚreturnc                 C   s   | dusJ ‚|   d¡S )z&convert c string back to python stringNzutf-8)Údecode)r   © r   úK/var/www/html/CropPilot/venv/lib/python3.10/site-packages/xgboost/compat.pyÚpy_str   s   
r   ÚinstanceÚmoduleÚnamec                 C   s"   | j }|j|k}|j|k}|o|S )z-Use string representation to identify a type.)Ú	__class__Ú
__module__Ú__name__)r   r   r   ÚclsÚis_same_moduleÚhas_same_namer   r   r   Úlazy_isinstance   s   

r   )Ú__version__)ÚBaseEstimator)ÚClassifierMixin)ÚRegressorMixin)ÚStratifiedKFold)ÚTagsTFc                   @   ó   e Zd ZdZdS )ÚXGBModelBasez+Dummy class for sklearn.base.BaseEstimator.N©r   r   Ú__qualname__Ú__doc__r   r   r   r   r"   @   ó    r"   c                   @   r!   )ÚXGBClassifierBasez-Dummy class for sklearn.base.ClassifierMixin.Nr#   r   r   r   r   r'   C   r&   r'   c                   @   r!   )ÚXGBRegressorBasez,Dummy class for sklearn.base.RegressorMixin.Nr#   r   r   r   r   r(   F   r&   r(   c                  C   sB   t j d¡du r
dS zddl} W dS  ty    t d¡ Y dS w )z#Check cuDF package available or notÚcudfNFr   Tz1Importing cuDF failed, use DMatrix instead of QDM)Ú	importlibÚutilÚ	find_specr)   ÚImportErrorÚ_loggerÚ	exception)r)   r   r   r   Úis_cudf_availableR   s   
þr0   c                  C   s8   t j d¡du r
dS zddl} W dS  ty   Y dS w )z#Check cupy package available or notÚcupyNFr   T)r*   r+   r,   r1   r-   ©r1   r   r   r   Úis_cupy_available`   s   ÿr3   c                  C   s   t ƒ stdƒ‚ddl} | S )zImport cupy.z,`cupy` is required for handling CUDA buffer.r   N)r3   r-   r1   r2   r   r   r   Úimport_cupym   s   r4   c                   C   ó   t j d¡du r
dS dS )z&Check pyarrow package available or notÚpyarrowNFT©r*   r+   r,   r   r   r   r   Úis_pyarrow_availablex   ó   r8   c                  C   ó   ddl } | S )z!Import pyarrow with memory cache.r   N)r6   )Úpar   r   r   Úimport_pyarrow€   ó   r<   c                  C   r:   )z Import pandas with memory cache.r   N)Úpandas)Úpdr   r   r   Úimport_pandasˆ   r=   r@   c                  C   r:   )z Import polars with memory cache.r   N)Úpolars)Úplr   r   r   Úimport_polars�   r=   rC   c                   C   r5   )z-Check the pandas package is available or not.r>   NFTr7   r   r   r   r   Úis_pandas_available˜   r9   rD   )Ú
csr_matrixÚdatac                 C   ó   t | ddƒS )Nzpolars.lazyframe.frameÚ	LazyFrame©r   ©rF   r   r   r   Ú_is_polars_lazyframe¨   ó   rK   c                 C   rG   )Nzpolars.series.seriesÚSeriesrI   rJ   r   r   r   Ú_is_polars_series¬   rL   rN   c                 C   s   t | ƒ}t| ddƒ}|p|S )Nzpolars.dataframe.frameÚ	DataFrame)rK   r   )rF   ÚlfÚdfr   r   r   Ú
_is_polars°   s   rR   zpa.Tablec                 C   rG   )Nzpyarrow.libÚTablerI   rJ   r   r   r   Ú	_is_arrow¶   rL   rT   c                 C   rG   )Núcudf.core.dataframerO   rI   rJ   r   r   r   Ú_is_cudf_dfº   rL   rV   c                 C   rG   )Núcudf.core.seriesrM   rI   rJ   r   r   r   Ú_is_cudf_ser¾   rL   rX   c                 C   s    t | ƒst| ƒott| ƒddƒS )z+Must go before both pandas and cudf checks.zcudf.pandas.fast_slow_proxyÚ_FastSlowProxyMeta)Ú_is_pandas_dfÚ_is_pandas_seriesr   ÚtyperJ   r   r   r   Ú_is_cudf_pandasÂ   s   
ÿr]   zpd.DataFramec                 C   ó   t | ddƒpt | ddƒS )Nzpandas.core.framerO   r>   rI   rJ   r   r   r   rZ   É   ó   ÿrZ   z	pd.Seriesc                 C   r^   )Nzpandas.core.seriesrM   r>   rI   rJ   r   r   r   r[   Ï   r_   r[   c                 C   rG   )Nzmodin.pandas.dataframerO   rI   rJ   r   r   r   Ú_is_modin_dfÕ   rL   r`   c                 C   rG   )Nzmodin.pandas.seriesrM   rI   rJ   r   r   r   Ú_is_modin_seriesÙ   rL   ra   c                    s*   t ‡ fdd„ttttttttt	t
f
D ƒƒS )zšWhether the input is a dataframe. Currently supported dataframes:

    - pandas
    - cudf
    - cudf.pandas
    - polars
    - pyarrow
    - modin


    c                 3   s   � | ]}|ˆ ƒV  qd S )Nr   )Ú.0ÚprJ   r   r   Ú	<genexpr>é   s
   € ÿ
ÿzis_dataframe.<locals>.<genexpr>)ÚanyrR   rN   rT   rV   rX   r]   rZ   r[   r`   ra   rJ   r   rJ   r   Úis_dataframeÝ   s   öþrf   c                 C   s
   t | dƒS )NÚ__cuda_array_interface__)ÚhasattrrJ   r   r   r   Ú_is_cupy_alikeú   s   
ri   Úvaluec           	      C   sn  t | d tjƒrtttj | ƒ}tj|dd�S tr(t | d tjƒr(tj| dd�S tr9t | d tj	ƒr9tj| dd�S trJt | d tj
ƒrJtj| dd�S t| d ƒsVt| d ƒrbddlm} || dd�S t| d ddƒsrt| d d	d
ƒr~ddlm} || dd�S t| d ƒr¬ddl}|jj ¡ }| D ]}t|j|ƒ}|jj}||ks¤J dƒ‚q�|j| dd�S tdt| d ƒ› �ƒ‚)zConcatenate row-wise.r   )ÚaxisÚcsr)ÚformatÚcsc)ÚconcatrU   rO   rW   rM   Nz*Concatenating arrays on different devices.zUnknown type: )Ú
isinstanceÚnpÚndarrayr   r   ÚconcatenateÚscipy_sparserE   ÚvstackÚ
csc_matrixÚspmatrixrZ   r[   r>   ro   r   r)   ri   r1   ÚcudaÚruntimeÚ	getDeviceÚdeviceÚidÚ	TypeErrorr\   )	rj   Ú	value_arrÚ	pd_concatÚCUDF_concatr1   ÚdÚvÚarrÚd_vr   r   r   ro   þ   s4   
ÿro   )Pr%   Ú	functoolsÚimportlib.utilr*   ÚloggingÚsysÚtypesÚtypingr   r   r   r   r   Únumpyrq   Ú_typingr   r	   r>   r?   r6   r;   Úversion_infoÚbytesÚstrr   Úboolr   Úsklearnr   Ú_sklearn_versionÚsklearn.baser   r"   r   r'   r   r(   Úsklearn.model_selectionr   ÚXGBStratifiedKFoldr-   Úsklearn.cross_validationÚsklearn.utilsr    Ú_sklearn_TagsÚobjectÚSKLEARN_INSTALLEDÚ	getLoggerr   r.   Úcacher0   r3   Ú
ModuleTyper4   r8   r<   r@   rC   rD   Úscipy.sparseÚsparsert   rE   Ú	scipy_csrrK   rN   rR   rT   rV   rX   r]   rZ   r[   r`   ra   rf   ri   ro   r   r   r   r   Ú<module>   sœ   ÿÿð

þ