Λ
    ΏAHj@  γ                  σH   d dl mZ d dlZd dlmZ d dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ  ej                  e«      5  d dlmZ ddd«       erd dlmZ d d	lmZ d d
lmZmZ d dlmZ ddZ e«        eddgd¬«      	 	 d	 	 	 	 	 	 	 	 	 dd«       «       Zy# 1 sw Y   SxY w)ι    )ΪannotationsN)ΪTYPE_CHECKING)Ϊdeprecate_nonkeyword_arguments)Ϊparse_into_expression)Ϊunstable)Ϊ	wrap_expr)ΪIterable)Ϊdate)ΪExprΪSeries)ΪIntoExprColumnc                σ   t        | t        j                  t        j                  f«      s;t        j                  d| gdt        j                  t        j
                  «      ¬«      } t        | t        j
                  ¬«      S )z"Convert into Expr of List of Date.Ϊ F)ΪstrictΪdtype)r   )Ϊ
isinstanceΪplr   r   ΪListΪDater   )Ϊholidayss    ϊQ/root/tools/cai/cai_env/lib/python3.12/site-packages/polars/functions/business.pyΪ_holidays_to_exprr      sM    δh€§‘¬"―)©)Π 4Τ5ά99R ( °EΔΗΑΜΟΙΣAQΤRά  ΄·±Τ9Π9σ    ΪstartΪendz1.27.0)Ϊallowed_argsΪversionc           	     σ    t        | «      }t        |«      }t        |«      }t        t        j                  ||t        |«      |«      «      S )u  
    Count the number of business days between `start` and `end` (not including `end`).

    .. warning::
        This functionality is considered **unstable**. It may be changed
        at any point without it being considered a breaking change.

    .. versionchanged:: 1.27.0
        Parameters after `start` and `end` should now be passed as keyword arguments.

    Parameters
    ----------
    start
        Start dates.
    end
        End dates.
    week_mask
        Which days of the week to count. The default is Monday to Friday.
        If you wanted to count only Monday to Thursday, you would pass
        `(True, True, True, True, False, False, False)`.
    holidays
        Holidays to exclude from the count. The Python package
        `python-holidays <https://github.com/vacanza/python-holidays>`_
        may come in handy here. You can install it with ``pip install holidays``,
        and then, to get all Dutch holidays for years 2020-2024:

        .. code-block:: python

            import holidays

            my_holidays = holidays.country_holidays("NL", years=range(2020, 2025))

        and pass `holidays=my_holidays` when you call `business_day_count`.

    Returns
    -------
    Expr

    Examples
    --------
    >>> from datetime import date
    >>> df = pl.DataFrame(
    ...     {
    ...         "start": [date(2020, 1, 1), date(2020, 1, 2)],
    ...         "end": [date(2020, 1, 2), date(2020, 1, 10)],
    ...     }
    ... )
    >>> df.with_columns(
    ...     business_day_count=pl.business_day_count("start", "end"),
    ... )
    shape: (2, 3)
    ββββββββββββββ¬βββββββββββββ¬βββββββββββββββββββββ
    β start      β end        β business_day_count β
    β ---        β ---        β ---                β
    β date       β date       β i32                β
    ββββββββββββββͺβββββββββββββͺβββββββββββββββββββββ‘
    β 2020-01-01 β 2020-01-02 β 1                  β
    β 2020-01-02 β 2020-01-10 β 6                  β
    ββββββββββββββ΄βββββββββββββ΄βββββββββββββββββββββ

    Note how the business day count is 6 (as opposed a regular day count of 8)
    due to the weekend (2020-01-04 - 2020-01-05) not being counted.

    You can pass a custom weekend - for example, if you only take Sunday off:

    >>> week_mask = (True, True, True, True, True, True, False)
    >>> df.with_columns(
    ...     business_day_count=pl.business_day_count(
    ...         "start", "end", week_mask=week_mask
    ...     ),
    ... )
    shape: (2, 3)
    ββββββββββββββ¬βββββββββββββ¬βββββββββββββββββββββ
    β start      β end        β business_day_count β
    β ---        β ---        β ---                β
    β date       β date       β i32                β
    ββββββββββββββͺβββββββββββββͺβββββββββββββββββββββ‘
    β 2020-01-01 β 2020-01-02 β 1                  β
    β 2020-01-02 β 2020-01-10 β 7                  β
    ββββββββββββββ΄βββββββββββββ΄βββββββββββββββββββββ

    You can also pass a list of holidays to exclude from the count:

    >>> from datetime import date
    >>> holidays = [date(2020, 1, 1), date(2020, 1, 2)]
    >>> df.with_columns(
    ...     business_day_count=pl.business_day_count("start", "end", holidays=holidays)
    ... )
    shape: (2, 3)
    ββββββββββββββ¬βββββββββββββ¬βββββββββββββββββββββ
    β start      β end        β business_day_count β
    β ---        β ---        β ---                β
    β date       β date       β i32                β
    ββββββββββββββͺβββββββββββββͺβββββββββββββββββββββ‘
    β 2020-01-01 β 2020-01-02 β 0                  β
    β 2020-01-02 β 2020-01-10 β 5                  β
    ββββββββββββββ΄βββββββββββββ΄βββββββββββββββββββββ
    )r   r   r   ΪplrΪbusiness_day_countΪlist)r   r   Ϊ	week_maskr   Ϊstart_pyexprΪ
end_pyexprΪholidays_pyexprs          r   r    r       sN    τT )¨Σ/Lά& sΣ+Jά'¨Σ1OάάΧΡΨΨάOΨσ		
σπ r   )r   z$Iterable[date] | pl.Expr | pl.SeriesΪreturnz
plr.PyExpr))TTTTTFF© )
r   ϊdate | IntoExprColumnr   r(   r"   zIterable[bool]r   zIterable[date] | Expr | Seriesr&   r   )Ϊ
__future__r   Ϊ
contextlibΪtypingr   Ϊpolarsr   Ϊpolars._utils.deprecationr   Ϊpolars._utils.parser   Ϊpolars._utils.unstabler   Ϊpolars._utils.wrapr   ΪsuppressΪImportErrorΪpolars._plrΪ_plrr   Ϊcollections.abcr	   Ϊdatetimer
   r   r   Ϊpolars._typingr   r   r    r'   r   r   ϊ<module>r8      sΔ   πέ "γ έ  γ έ Dέ 5έ +έ (ΰZΧΡΣ%ρ έχρ έ(έη#έ-σ:ρ 
Ω¨g°uΠ-=ΐxΤPπ !MΨ/1π	rΨ πrΰ	πrπ πrπ -π	rπ
 
ςrσ Qσ ρrχ)π ϊs   ΏBΒB!