
    9iH              $          S SK JrJrJrJrJr  S SKrS SKr	S SK
Jr  S SKJr  S SKJrJrJr  SSKJrJrJr  \" S5      (       a  S SKr\" S	5      (       a  S S
KJr  Sr\R6                  " SSS\" 5       \" S 5      /S9r\R6                  " SSSS9r\R6                  " SSS\" \R<                  " S5      S9S9r\R6                  " SSS\" \R<                  " S5      S9S9r \R6                  " SSSS9r!\R6                  " SSSS9r"\R6                  " SSSS9r#\R6                  " SSSS9r$\R6                  " SSS\	R                   " \RJ                  " S5      S9\" S5      /S9r&\R6                  " S SS\	R                   " \RJ                  " S5      S9\" S5      /S9r'\RP                  \RR                  \RT                  \RV                  \RX                  \RZ                  \R\                  \R^                  \\\\ \!\"\#\$\&\'/r0S!\Rb                  4S" jr2S!\Rb                  4S# jr3S!\Rb                  4S$ jr4S!\Rb                  4S% jr5S!\Rb                  4S& jr6S!\Rb                  4S' jr7S!\Rb                  4S( jr8S!\Rb                  4S) jr9S!\Rb                  4S* jr:S!\Rb                  4S+ jr;S!\Rb                  4S, jr<\" S5      S!\Rb                  4S- j5       r=\" S5      S!\Rb                  4S. j5       r>S!\Rb                  4S/ jr?S!\Rb                  4S0 jr@\2\3\4\5\6\7\?\@\8\9\:\;\<\=\>S1.rA     SKS2\\	R                  \	R                  4   S3\\D   S4\\\\D   \D4      S5\\\D\E4      S6\FS7\\\G\\D\G4   4      S8\	R                  4S9 jjrH            SLS:\	R                  S;\\D   S3\\D   S<\\\\D   \D4      S=\\\\D   \D4      S>\\\\D   \D4      S?\\\\D   \D4      S@\\\\D   \D4      SA\\\\D   \D4      S5\\\D\E4      SB\FSC\DSD\ES8\\D\\\	R                  \\D\I4   4      4   4SE jjrJS8\\	R                  /\L4   4SF jrM\" S	5       SMSG\S5\\\D\E4      S?\\D   SH\ESI\FS8\4SJ jj5       rNg)N    )CallableDictListOptionalUnionN)Version)holiday)
DateOffsetDayEaster   )function_requires_depsget_dep_versionis_dep_availablezchinese-calendarzscikit-learn)StandardScaler   zEaster Sunday   )monthdayoffsetzNew Years Day)r   r   	Superbowl   )weekdayzMothers DayzIndependence Day      	Christmas         zNew Years Eve   zBlack Friday   zCyber Mondayxc                     U R                   $ N)yearr"   s    h/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/inference/models/common/ts/funcs.py	_cal_yearr(   M        66M    c                     U R                   $ r$   r   r&   s    r'   
_cal_monthr-   S   s     77Nr*   c                     U R                   $ r$   r   r&   s    r'   _cal_dayr0   Y   s     55Lr*   c                     U R                   $ r$   hourr&   s    r'   	_cal_hourr4   _   r)   r*   c                     U R                   $ r$   	dayofweekr&   s    r'   _cal_weekdayr8   e   s     ;;r*   c                     U R                   $ r$   )quarterr&   s    r'   _cal_quarterr;   k   s     99r*   c                 &    U R                   S-  S-
  $ )Ng      7@      ?r2   r&   s    r'   _cal_hourofdayr>   q   s     66D=3r*   c                 &    U R                   S-  S-
  $ )Ng      @r=   r6   r&   s    r'   _cal_dayofweekr@   w   s     ;;s""r*   c                 &    U R                   S-  S-
  $ )Ng      >@r=   r/   r&   s    r'   _cal_dayofmonthrB   }   s     554<#r*   c                 &    U R                   S-  S-
  $ )Ng     v@r=   )	dayofyearr&   s    r'   _cal_dayofyearrE      s     ;;$$r*   c                 &    U R                   S-  S-
  $ )Ng     I@r=   )
weekofyearr&   s    r'   _cal_weekofyearrH      s     <<$$$r*   c                 @    [        [        R                  " U 5      5      $ r$   )floatchinese_calendar
is_holidayr&   s    r'   _cal_holidayrM           !,,Q/00r*   c                 @    [        [        R                  " U 5      5      $ r$   )rJ   rK   
is_workdayr&   s    r'   _cal_workdayrQ      rN   r*   c                 &    U R                   S-  S-
  $ )N;   r=   )minuter&   s    r'   _cal_minuteofhourrU      s     88b=3r*   c                 &    U R                   S-  S-
  $ )Ng      &@r=   r,   r&   s    r'   _cal_monthofyearrW      s     77T>Cr*   )r%   r   r   r3   r   r:   minuteofhourmonthofyear	hourofdayr7   
dayofmonthrD   rG   rL   rP   datatime_col
value_colsfreqdrop_tail_nandtypereturnc                 \   SnUc_  [        U [        R                  5      (       a  U R                  5       nOPU R                  SS2U R
                  U:g  4   R                  5       nO!U R                  SS2U4   R                  5       nU(       a=  XR
                  ;  a  [        SR                  U5      5      eU R                  SS2U4   nOU R                  n[        R                  " UR                  [        R                  5      (       a*  [        U[        5      (       a  UR                  [        5      n[        R                  " UR                  [        R                  5      (       a}  U(       a'  [        U[        5      (       a  US:  a  [        S5      eOSn[!        U5      [#        U5      U-   pX-
  U-  [%        U 5      :w  a  [        S5      e[        R&                  " XUS9n
O[        R                  " UR                  [        R(                  5      (       d4  [        R                  " UR                  [        R*                  5      (       a  [        R,                  " USS9n[        R.                  " U5      n
U(       a!  [        U[        5      (       d  [        S	5      eO>[        R0                  " U
5      nUc  [        S
5      eUS   S:X  a  USS nO[        S5      e[        U[        R                  5      (       a  UR3                  5       nUR5                  U
SS9  UR7                  SS9  U$ )a?  Transforms a DataFrame or Series into a time-indexed DataFrame.

Args:
    data (Union[pd.DataFrame, pd.Series]): The input data containing time series information.
    time_col (Optional[str]): The column name representing time information. If None, uses the index.
    value_cols (Optional[Union[List[str], str]]): Columns to extract as values. If None, uses all except time_col.
    freq (Optional[Union[str, int]]): The frequency of the time series data.
    drop_tail_nan (bool): If True, drop trailing NaN values from the data.
    dtype (Optional[Union[type, Dict[str, type]]]): Enforce a specific data type on the resulting DataFrame.

Returns:
    pd.DataFrame: A DataFrame with time as the index and specified value columns.

Raises:
    ValueError: If the time column doesn't exist, or if frequency cannot be inferred.

Nz0The time column: {} doesn't exist in the `data`!r   zOThe type of `freq` should be `int` when the type of `time_col` is `RangeIndex`.z5The number of rows doesn't match with the RangeIndex!)startstopstepT)infer_datetime_formatzRThe type of `freq` should be `str` when the type of `time_col` is `DatetimeIndex`.z7Failed to infer the `freq`. A valid `freq` is required.r   -z"The type of `time_col` is invalid.)inplace)
isinstancepdSeriescopyloccolumns
ValueErrorformatindexnp
issubdtypera   integerstrastypeintminmaxlen
RangeIndexobject_
datetime64to_datetimeDatetimeIndex
infer_freqto_frame	set_index
sort_index)r\   r]   r^   r_   r`   ra   series_datatime_col_vals	start_idxstop_idx
time_indexs              r'   load_from_one_dataframer      s   4 KdBII&&))+K((1dllh&>#>?DDFKhhq*}-224 <<'BII(S  H-

 
}}](("**55*T3:O:O%,,S1 
}}](("**55dC((D1H e  -5
 D!-0#m2Dt2K8 D(CI5TUU]]M
 
}**BJJ	7	72==R]]< < }DQ%%m4
dC(( h  ) ==,D| M  Aw#~ABx =>> +ryy))!**, *d34(r*   dfgroup_idtarget_cols	label_colobserved_cov_colsfeature_colsknown_cov_colsstatic_cov_colsfill_missing_datesfillna_methodfillna_window_sizec           
         / nUbB  X   R                  5       nU H)  nUR                  X U   R                  U/5         5        M+     OU /n/ nU(       a1  [        U[        5      (       a  [        U5      S:  a  [        S5      eUnU(       a  UnU GH+  n SnSnSn[        5       n[        X5Xx/5      (       d2  [        U UU R                   Vs/ s H  nUU:w  d  M  UPM     snU	5      nOU(       a  [        U UUU	5      nU(       a  [        U UUU	5      nU(       a  [        U UUU	5      nU(       aw  [        U[        5      (       a  U/nU HY  nUU R                  ;  d&  [        [        R                   " U U   5      5      S:w  a  [        S5      eU U   R                  S   UU'   M[     UR                  UUUUS.5        GM.     US   $ s  snf )ai  Loads and processes time series data from a DataFrame.

This function extracts and organizes time series data from a given DataFrame.
It supports optional grouping and extraction of specific columns as features.

Args:
    df (pd.DataFrame): The input DataFrame containing time series data.
    group_id (Optional[str]): Column name used for grouping the data.
    time_col (Optional[str]): Name of the time column.
    target_cols (Optional[Union[List[str], str]]): Columns to be used as target.
    label_col (Optional[Union[List[str], str]]): Columns to be used as label.
    observed_cov_cols (Optional[Union[List[str], str]]): Columns for observed covariates.
    feature_cols (Optional[Union[List[str], str]]): Columns to be used as features.
    known_cov_cols (Optional[Union[List[str], str]]): Columns for known covariates.
    static_cov_cols (Optional[Union[List[str], str]]): Columns for static covariates.
    freq (Optional[Union[str, int]]): Frequency of the time series data.
    fill_missing_dates (bool): Whether to fill missing dates in the time series.
    fillna_method (str): Method to fill missing values ('pre' or 'post').
    fillna_window_size (int): Window size for filling missing values.
    **kwargs: Additional keyword arguments.

Returns:
    Dict[str, Optional[Union[pd.DataFrame, Dict[str, any]]]]: A dictionary containing processed time series data.
Nr   z"The length of label_col must be 1.zIStatic covariate columns data is not in columns or schema is not correct!r   )past_targetobserved_cov_numericknown_cov_numericstatic_cov_numeric)uniqueappendisinrj   rv   r{   rp   dictanyr   ro   rs   iloc)r   r   r]   r   r   r   r   r   r   r_   r   r   r   kwargsdfsgroup_uniquecolumnrestargetobserved_cov	known_cov
static_covacols                           r'   load_from_dataframer     s   R C |**,"FJJrX,++VH567 # d C i%%#i.1*<ABB ( 	V
 KNTUU,JJ8Jq!x-J8	F 0	 !6%	  3"		 os33'6&7O*C"**,BIIbg4F0G10L(g  ')gll1oJsO + 	

%(4%.&0		
c t q6M_ 9s   
GGc                 D   ^  S[         R                  S[        4U 4S jjnU$ )a  Creates a function to calculate the distance in days to the nearest holiday.

This function generates a closure that computes the number of days from
a given date index to the nearest holiday within a defined window.

Args:
    holiday: An object that provides a `dates` method, which returns the
        dates of holidays within a specified range.

Returns:
    Callable[[pd.Timestamp], float]: A function that takes a date index
    as input and returns the distance in days to the nearest holiday.
rr   rb   c                    > TR                  U [        R                  " [        S9-
  U [        R                  " [        S9-   5      n[	        U5      S:w  d   SU  S35       e[        XS   -
  R                  5      $ )a]  Calculates the distance in days from a given date index to the nearest holiday.

Args:
    index (pd.Timestamp): The date index for which the distance to the
        nearest holiday should be calculated.

Returns:
    float: The number of days to the nearest holiday.

Raises:
    AssertionError: If no holiday is found within the specified window.
)daysr   z&No closest holiday for the date index z found.)datesrk   	Timedelta
MAX_WINDOWr{   rJ   r   )rr   holiday_dater	   s     r'   _distance_to_day._distance_to_holiday.<locals>._distance_to_day  sy     }}BLLj11BLLj11

 "	C3E7'B	C" e1o-3344r*   )rk   	TimestamprJ   )r	   r   s   ` r'   _distance_to_holidayr     s"    5 5 50 r*   datasetextend_pointsri   c           
      d  ^ U nU(       d  U R                  5       nUS   nU(       d  US   R                  R                  5       nOUR                  R                  5       nUR                  S   n[        R
                  " Xx   R                  [        R                  5      (       a  [        S5      eU(       d  Ub  UO[        R                  " Xx   5      n[        S5      n	[        U	5      [        S5      :  a/  [        R                  " Xx   S   UUS-   S	US
9R                  5       n
O.[        R                  " Xx   S   UUS-   S	US9R                  5       n
[        R                  " Xz/5      nU GH  mTS:w  a  Xx   R                  U4S j5      nXx   Ul        US   c3  [        R                   " UR#                  T5      UR                  S9US'   Mc  UR#                  T5      R%                  US   R                  5      US   T'   M  / n['        [(        5       H  u  pXx   R                  [+        U5      5      nXx   Ul        UR-                  TS-   [/        U5      -   5        US   cB  [        R                   " UR#                  TS-   [/        U5      -   5      UR                  S9US'   M  UR#                  T5      R%                  US   R                  5      US   TS-   [/        U5      -   '   M     [1        5       nUR3                  US   U   5        UR5                  US   U   5      US   U'   GM     U$ )a#  Transforms the time column of a dataset into time features.

This function extracts time-related features from the time column in a
dataset, optionally extending the time series for future points and
normalizing holiday distances.

Args:
    dataset (Dict): Dataset to be transformed.
    freq: Optional[Union[str, int]]: Frequency of the time series data. If not provided,
        the frequency will be inferred.
    feature_cols (List[str]): List of feature columns to be extracted.
    extend_points (int): Number of future points to extend the time series.
    inplace (bool): Whether to perform the transformation inplace. Default is False.

Returns:
    Dict: The transformed dataset with time features added.

Raises:
    ValueError: If the time column is of an integer type instead of datetime.
r   r   r   z\The time_col can't be the type of numpy.integer, and it must be the type of numpy.datetime64pandasz1.4r   right)rd   r_   periods	inclusivename)rd   r_   r   closedr   holidaysc                 "   > [         T   " U 5      $ r$   )CAL_DATE_METHOD)r"   ks    r'   <lambda>time_feature.<locals>.<lambda>
  s    /!2DQ2Gr*   )rr   _)rm   rr   r   ro   rs   rt   ra   ru   rp   rk   r   r   r   
date_rangeconcatapply	DataFramerenamereindex	enumerateHOLIDAYSr   r   rv   r   fit	transform)r   r_   r   r   ri   new_tskcovtf_kcovr]   
pd_versionextend_timevholidays_coliHscalerr   s                   @r'   time_featurer     s   8 F%&D'--668**%%'q!H	}}W&,,bjj99j
 	
 'tR]]7;L-M$X.
:'%.0--'+%)! hj  --'+%) hj  ))W23 
?!''(GHA'AG)*2.0ll188A;agg.V*+12!1D1D./552*+A. L!(+%++,@,CD!+##AGc!f$45-.624,,S3q6!12!''3F./ EFHHQKDWDW2399EF./C#a&0@A , $%FJJv12<@A8>8H8H*+L99F&'59 > Mr*   )NNNFN)NNNNNNNNNFpre
   )F)Otypingr   r   r   r   r   numpyrs   r   rk   packaging.versionr   pandas.tseriesr	   hdpandas.tseries.offsetsr
   r   r   
utils.depsr   r   r   rK   sklearn.preprocessingr   r   HolidayEasterSundayNewYearsDaySU	SuperBowl
MothersDayIndependenceDayChristmasEveChristmasDayNewYearsEveTHBlackFridayCyberMondayEasterMonday
GoodFridayUSColumbusDay
USLaborDayUSMartinLutherKingJrUSMemorialDayUSPresidentsDayUSThanksgivingDayr   r~   r(   r-   r0   r4   r8   r;   r>   r@   rB   rE   rH   rM   rQ   rU   rW   r   r   rl   rv   rx   booltyper   r   r   r   rJ   r   r    r*   r'   <module>r      s    9 8   % ( : : U U&''N##4
zz/68SQRVBTUjjq9JJ{!:beeTUh;WX	ZZ*RUU1X*F
 **/qa@zz+RR8zz+RR8jj;jj
	MM"%%(+SV4	 jj
	MM"%%(+SV4	 OOMMMM%,	}}	}}	}}	}}	}}	}}	}}#	}}#	}}%	}}%%	}}% *+1	}}1 ,1 *+1	}}1 ,1	}} 	}}  %#!!* #26&*48_
bii'
(_sm_ tCy#~./_ 5c?
#	_
 _ E$S$Y/01_ \\_H #"37159=486:7;&*$ {
{sm{ sm{ %S	3/0	{
 d3in-.{  d3in 56{ 5cC01{ U49c>23{ eDIsN34{ 5c?
#{ { { { 
#xbllDcN:;<
<={|'Xr||ne.C%D 'T ' ``
5c?
#` s)` 	`
 ` 
` (`r*   