
    }ochf                    l   d Z ddlmZ ddlmZmZ ddlZddlmZm	Z	m
Z
 ddlZddlmZ ddlmZmZmZ ddlmZmZmZmZmZ dd	lmZ dd
lmZmZ ddlmZ ddl m!Z!m"Z"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/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z;m<Z< ddl=m>c m?Z@ ddlAmBZB ddlCm>c mDc mEZF ddlCmGZGmHZHmIZImJZJ ddlKmLZLmMZM ddlNmOZOmPZP ddlQmRZR ddlSmTZTmUZU erddlVmWZW ddlXmYZYmZZZm[Z[m\Z\m]Z]  e^eFj                        Z_e_j                  ddd ej                  d      d       d Zbd  Zcd! Zd ee<d"   dd#e_d$   d%d& ej                  d'      d(z         ePd)d*ge;d+,       ePg d-e;       ePd.d/ge;d+0       G d1 deO                                  Zed5d2Zfd5d3Zg	 	 	 	 	 	 d6	 	 	 	 	 d7d4Zhy)8z define the IntervalIndex     )annotations)leltN)TYPE_CHECKINGAnyLiteral)lib)IntervalIntervalMixinIntervalTree)
BaseOffsetPeriod	Timedelta	Timestamp	to_offset)InvalidIndexError)Appendercache_readonly)rewrite_exception)find_common_typeinfer_dtype_from_scalarmaybe_box_datetimelikemaybe_downcast_numericmaybe_upcast_numeric_to_64bit)
ensure_platform_intis_float_dtype
is_integeris_integer_dtypeis_list_like	is_numberis_object_dtype	is_scalaris_string_dtypepandas_dtype)DatetimeTZDtypeIntervalDtype)is_valid_na_for_dtypeunique)validate_periods)IntervalArray_interval_shared_docs)is_valid_positional_slice)Index_index_shared_docsensure_indexmaybe_extract_name)DatetimeIndex
date_range)ExtensionIndexinherit_names)
MultiIndex)TimedeltaIndextimedelta_range)Hashable)DtypeDtypeObjIntervalClosedTypeSelfnptIntervalIndexz"IntervalIndex or list of IntervalszX         name : object, optional
              Name to be stored in the index.
         )klassqualnametarget_klassnamec                   t        | dt        |             }t        | t        t        f      rd}t        |      }t        j                  |d      st        |t              r| t        j                  dd      z   S t        |      r| dz   S t        |      r$t        j                  | t        j                        S t        dt!        t        |                    Ndtypezdatetime64[ns]mM   nsz%cannot determine next label for type getattrtype
isinstancer   r   r$   r	   is_np_dtyper%   nptimedelta64r   r   	nextafterinf	TypeErrorreprlabelrF   s     k/mnt/ACDE16A4DE16673C/PROJECTS/MIS_PORTAL/venv/lib/python3.12/site-packages/pandas/core/indexes/interval.py_get_next_labelrX   v   s    E7DK0E%)Y/0 E
ud#z%'Ir~~a...	%	 qy		||E266**?T%[@Q?RSTT    c                   t        | dt        |             }t        | t        t        f      rd}t        |      }t        j                  |d      st        |t              r| t        j                  dd      z
  S t        |      r| dz
  S t        |      r%t        j                  | t        j                         S t        dt!        t        |                    rE   rJ   rU   s     rW   _get_prev_labelr[      s    E7DK0E%)Y/0 E
ud#z%'Ir~~a...	%	 qy		||EBFF7++?T%[@Q?RSTTrY   c                &     | j                   di |S )zv
    This is called upon unpickling, rather than the default which doesn't have
    arguments and breaks __new__.
     )from_arrays)clsds     rW   _new_IntervalIndexra      s    
 3??QrY   classz>Immutable index of intervals that are closed on the same side.rC   zis_overlapping
values
 a7      Examples
    --------
    A new ``IntervalIndex`` is typically constructed using
    :func:`interval_range`:

    >>> pd.interval_range(start=0, end=5)
    IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]],
                  dtype='interval[int64, right]')

    It may also be constructed using one of the constructor
    methods: :meth:`IntervalIndex.from_arrays`,
    :meth:`IntervalIndex.from_breaks`, and :meth:`IntervalIndex.from_tuples`.

    See further examples in the doc strings of ``interval_range`` and the
    mentioned constructor methods.
    )r@   summaryrC   extra_attributesextra_methodsexamples
set_closed	to_tuplesT)wrap)	__array__overlapscontainsclosed_leftclosed_right	open_left
open_rightis_emptyis_non_overlapping_monotonicclosed)cachec            	      j    e Zd ZU dZded<   ded<   ded<   ded<   ded<   ded	<   d
ed<   d
ed<   dZeZ	 	 	 	 	 d<	 	 	 	 	 	 	 	 	 	 	 d=dZe	 e
ed   d  ej                  d       ej                  d      dz        	 	 	 	 d>	 	 	 	 	 	 	 	 	 d?d              Ze	 e
ed   d  ej                  d       ej                  d      dz        	 	 	 	 d>	 	 	 	 	 	 	 	 	 d@d              Ze	 e
ed   d  ej                  d       ej                  d      dz        	 	 	 	 d>	 	 	 	 	 	 	 	 	 d@d              ZedAd       ZdBdZdCdZedDd       Zd ZedEd       Z e
ej4                  j6                        dFdGd        ZedHd!       ZedHd"       ZedHd#       ZdHd$Zd% Z dIdJd&Z!dKd'Z"	 	 	 dL	 	 	 	 	 	 	 	 	 dMd(Z# e
e$d)   e%z        	 	 	 	 dNd*       Z&dOd+Z'	 	 	 	 dNd,Z(edHd-       Z)d.Z*dP fd/Z+edHd0       Z,dQd1Z-dRd2Z.edSd3       Z/edSd4       Z0edSd5       Z1edSd6       Z2d7 Z3dTd8Z4dTd9Z5dUd:Z6d; Z7 xZ8S )Vr?   intervalindexr<   rt   boolrs   rn   ro   rp   rq   r+   _data_valuesFc                    t        |||       }t        d| j                        5  t        |||||      }d d d        | j	                  |      S # 1 sw Y   xY w)Nr+   )rt   copyrF   verify_integrity)r1   r   __name__r+   _simple_new)r_   datart   rF   r|   rC   r}   arrays           rW   __new__zIntervalIndex.__new__   sa     "$c2= 	!!1E	 ud++	 	s   AAfrom_breakszY
             name : str, optional
                  Name of the resulting IntervalIndex.z        Examples
        --------
        >>> pd.IntervalIndex.from_breaks([0, 1, 2, 3])
        IntervalIndex([(0, 1], (1, 2], (2, 3]],
                      dtype='interval[int64, right]')
        )r@   rC   rg   c                    t        d| j                        5  t        j                  ||||      }d d d        | j	                  |      S # 1 sw Y   xY wNr+   )rt   r|   rF   rC   )r   r~   r+   r   r   )r_   breaksrt   rC   r|   rF   r   s          rW   r   zIntervalIndex.from_breaks   sU    : = 	!--vDE	 u400		 	   AAr^   z        Examples
        --------
        >>> pd.IntervalIndex.from_arrays([0, 1, 2], [1, 2, 3])
        IntervalIndex([(0, 1], (1, 2], (2, 3]],
                      dtype='interval[int64, right]')
        c                    t        d| j                        5  t        j                  |||||      }d d d        | j	                  |      S # 1 sw Y   xY w)Nr+   )r|   rF   r   )r   r~   r+   r^   r   )r_   leftrightrt   rC   r|   rF   r   s           rW   r^   zIntervalIndex.from_arrays  sW    < = 	!--eV$eE	 u400		 	s   AAfrom_tuplesz        Examples
        --------
        >>> pd.IntervalIndex.from_tuples([(0, 1), (1, 2)])
        IntervalIndex([(0, 1], (1, 2]],
                       dtype='interval[int64, right]')
        c                    t        d| j                        5  t        j                  ||||      }d d d        | j	                  |      S # 1 sw Y   xY wr   )r   r~   r+   r   r   )r_   r   rt   rC   r|   rF   arrs          rW   r   zIntervalIndex.from_tuples<  sU    : = 	Y++DdRWXC	Ys..	Y 	Yr   c                    | j                  | j                        }t        |      }| j                  | j                        }t        |      }t	        ||| j
                        S )Nrt   )_maybe_convert_i8r   r   r   r   rt   )selfr   r   s      rW   _enginezIntervalIndex._engine`  sS     %%dii0,T2&&tzz2-e4D%<<rY   c                    t        |       t        |t              s#t        || j                        r| j
                  S y	 | j                  |       y# t        $ r Y yw xY w)z
        return a boolean if this key is IN the index
        We *only* accept an Interval

        Parameters
        ----------
        key : Interval

        Returns
        -------
        bool
        FT)hashrM   r
   r'   rF   hasnansget_locKeyError)r   keys     rW   __contains__zIntervalIndex.__contains__i  sV     	S	#x($S$**5||#	LL 		s    A 	AAc                l    | j                   |   }t        |       j                  || j                        S )zH
        Fastpath for __getitem__ when we know we have a slice.
        r   )ry   rL   r   _name)r   slobjress      rW   _getitem_slicezIntervalIndex._getitem_slice  s0     jjDz%%c

%;;rY   c                `    t        j                  | j                  | j                  gddg      S )Nr   r   )names)r6   r^   r   r   r   s    rW   _multiindexzIntervalIndex._multiindex  s'    %%tyy$**&=fgEVWWrY   c                    | j                   | j                  | j                  | j                  d}t        t        |       |fd fS )N)r   r   rt   rC   )r   r   rt   rC   ra   rL   )r   r`   s     rW   
__reduce__zIntervalIndex.__reduce__  s<    IIZZkkII	
 "DJ?D88rY   c                     y)z4Return a string of the type inferred from the valuesintervalr]   r   s    rW   inferred_typezIntervalIndex.inferred_type  s     rY   c                t    | j                   j                  |      | j                  j                  |      z   S )N)deep)r   memory_usager   )r   r   s     rW   r   zIntervalIndex.memory_usage  s4     yy%%4%04::3J3JPT3J3UUUrY   c                &    | ddd   j                   S )z
        Return True if the IntervalIndex is monotonic decreasing (only equal or
        decreasing values), else False
        N)is_monotonic_increasingr   s    rW   is_monotonic_decreasingz%IntervalIndex.is_monotonic_decreasing  s     DbDz111rY   c                ^   | j                   }| j                  }| j                         j                         dkD  ry|j                  s|j                  ryt               }t        j                  |j                  d            d   }|D ]#  }||   ||   f}||v r y|j                  |       % y)zX
        Return True if the IntervalIndex contains unique elements, else False.
        rH   FT)keepr   )
r   r   isnasum	is_uniquesetrO   where
duplicatedadd)r   r   r   
seen_pairs	check_idxidxpairs          rW   r   zIntervalIndex.is_unique  s    
 yy

99;??q >>U__U
HHT__%_89!<	 	!CIuSz*Dz!NN4 		! rY   c                .    | j                   j                  S )a  
        Return True if the IntervalIndex has overlapping intervals, else False.

        Two intervals overlap if they share a common point, including closed
        endpoints. Intervals that only have an open endpoint in common do not
        overlap.

        Returns
        -------
        bool
            Boolean indicating if the IntervalIndex has overlapping intervals.

        See Also
        --------
        Interval.overlaps : Check whether two Interval objects overlap.
        IntervalIndex.overlaps : Check an IntervalIndex elementwise for
            overlaps.

        Examples
        --------
        >>> index = pd.IntervalIndex.from_tuples([(0, 2), (1, 3), (4, 5)])
        >>> index
        IntervalIndex([(0, 2], (1, 3], (4, 5]],
              dtype='interval[int64, right]')
        >>> index.is_overlapping
        True

        Intervals that share closed endpoints overlap:

        >>> index = pd.interval_range(0, 3, closed='both')
        >>> index
        IntervalIndex([[0, 1], [1, 2], [2, 3]],
              dtype='interval[int64, both]')
        >>> index.is_overlapping
        True

        Intervals that only have an open endpoint in common do not overlap:

        >>> index = pd.interval_range(0, 3, closed='left')
        >>> index
        IntervalIndex([[0, 1), [1, 2), [2, 3)],
              dtype='interval[int64, left]')
        >>> index.is_overlapping
        False
        )r   is_overlappingr   s    rW   r   zIntervalIndex.is_overlapping  s    ` ||***rY   c                    t        |dd      }t        |t              st        |t              r| j	                  |j
                        S t        t        t        t        f}t        ||      S )a	  
        Check if a given key needs i8 conversion. Conversion is necessary for
        Timestamp, Timedelta, DatetimeIndex, and TimedeltaIndex keys. An
        Interval-like requires conversion if its endpoints are one of the
        aforementioned types.

        Assumes that any list-like data has already been cast to an Index.

        Parameters
        ----------
        key : scalar or Index-like
            The key that should be checked for i8 conversion

        Returns
        -------
        bool
        rF   N)
rK   rM   r&   r
   _needs_i8_conversionr   r   r   r2   r7   )r   r   	key_dtypei8_typess       rW   r   z"IntervalIndex._needs_i8_conversion  sU    $ C$/	i/:c83L,,SXX66y-H#x((rY   c                   t        |      rt        |      }t        |      }| j                  |      s|S t	        |      }t        |dd      }t        |t              st        |t              rc| j                  |j                        }| j                  |j                        }|rt        nt        j                  } |||| j                        S |rt        |      \  }}t        |t               r|j"                  }nt        |t$              r|j&                  }nt        |t(        j*                  t(        j,                  f      r[|j/                  d      }nI|j0                  t3        |j4                        }}|j6                  r|j9                  |j:                         }| j0                  j<                  }||k7  rt?        d| d|       |S )a  
        Maybe convert a given key to its equivalent i8 value(s). Used as a
        preprocessing step prior to IntervalTree queries (self._engine), which
        expects numeric data.

        Parameters
        ----------
        key : scalar or list-like
            The key that should maybe be converted to i8.

        Returns
        -------
        scalar or list-like
            The original key if no conversion occurred, int if converted scalar,
            Index with an int64 dtype if converted list-like.
        rF   Nr   i8z)Cannot index an IntervalIndex of subtype z with values of dtype ) r   r0   r   r   r"   rK   rM   r&   r
   r   r   r   r?   r^   rt   r   r   ordinalr   _valuerO   
datetime64rP   viewrF   r.   asi8r   r   _isnansubtype
ValueError)	r   r   scalarr   r   r   constructorkey_i8r   s	            rW   r   zIntervalIndex._maybe_convert_i8  s   " s#C/4C((-J3C$/	i/:c83L))#((3D**3995E&,(-2K2KKeDKK   7 <Iv#v&FI.FR]]BNN$CDT* !$		5?vI{{  szzk2
 **$$i;G9 E##,+/ 
 rY   c                   | j                   st        d      t        |t        t        f      rt        d      |dk(  r| j                  j                  s|dk(  r:| j                  j                  s$| j                  }| j                  r/t        |      }n#| j                  }| j                  rt        |      }|j                  ||      S )Nzrcan only get slices from an IntervalIndex if bounds are non-overlapping and all monotonic increasing or decreasingz,Interval objects are not currently supportedr   r   )rs   r   rM   r   r?   NotImplementedErrorr   r   r   rq   rX   rp   r[   _searchsorted_monotonic)r   rV   sidesub_idxs       rW   r   z%IntervalIndex._searchsorted_monotonicQ  s    00M 
 em];<%&TUU
 FNtyy@@GODII$E$EjjG'.iiG~~'...ud;;rY   c                n   | j                  |       t        |t              rX| j                  |j                  k7  rt	        |      | j
                  |j
                  k(  | j                  |j                  k(  z  }nt        || j                        r| j                         }nX| j                  rt        nt        }| j                  rt        nt        }	  || j
                  |       ||| j                        z  }|j                         }|dk(  rt	        |      |dk(  r|j!                         S t#        j$                  |j'                  d            }t        |t(              r6|j*                  *t)        |j,                  t/        |       |j0                        }|S # t        $ r}t	        |      |d}~ww xY w)a  
        Get integer location, slice or boolean mask for requested label.

        Parameters
        ----------
        key : label

        Returns
        -------
        int if unique index, slice if monotonic index, else mask

        Examples
        --------
        >>> i1, i2 = pd.Interval(0, 1), pd.Interval(1, 2)
        >>> index = pd.IntervalIndex([i1, i2])
        >>> index.get_loc(1)
        0

        You can also supply a point inside an interval.

        >>> index.get_loc(1.5)
        1

        If a label is in several intervals, you get the locations of all the
        relevant intervals.

        >>> i3 = pd.Interval(0, 2)
        >>> overlapping_index = pd.IntervalIndex([i1, i2, i3])
        >>> overlapping_index.get_loc(0.5)
        array([ True, False,  True])

        Only exact matches will be returned if an interval is provided.

        >>> index.get_loc(pd.Interval(0, 1))
        0
        Nr   rH   u1)_check_indexing_errorrM   r
   rt   r   r   r   r'   rF   r   rn   r   r   ro   rS   r   argmaxr	   maybe_booleans_to_slicer   slicestopstartlenstep)r   r   maskop_leftop_righterrmatchesr   s           rW   r   zIntervalIndex.get_locn  sR   J 	""3'c8${{cjj(sm#II)djjCII.EFD"3

399;D !,,b"G!..rBH-tyy#.#tzz1JJ
 ((*a<3-a<;;= ))$))D/:c5!chh&6		3t9chh7C
  -sm,-s   'F 	F4#F//F4c                X   t        |t              r| j                  |      }t        |      S t        |j                        sVt        |j                        sA| j                  |      }| j                  j                  |j                        }t        |      S | j                  |      d   S )Nr   )rM   r?   _get_indexer_unique_sidesr!   rF   r#   r   r   get_indexervalues_get_indexer_pointwiser   )r   targetmethodlimit	toleranceindexers         rW   _get_indexerzIntervalIndex._get_indexer  s     fm,
 44V<G #7++ "&,,/?6<<3P ++F3Fll..v}}=G #7++ ..v6q99rY   get_indexer_non_uniquec                z   t        |      }| j                  |      s%| j                  |      s| j                  |d d      S t	        |t
              re| j                  j                  r>| j                  j                  r(| j                  |      }|dk(  j                         d   }n| j                  |      S t        |j                        s| j                  |      s| j                  |      S | j                  |      }| j                  j!                  |j"                        \  }}t%        |      t%        |      fS )NFr(   r   r   )r0   _should_compare_should_partial_index_get_indexer_non_comparablerM   r?   r   r   r   r   nonzeror   r!   rF   r   r   r   r   r   )r   r   r   missings       rW   r   z$IntervalIndex.get_indexer_non_unique  s    f%##F+D4N4Nv4V 33FD3OO.yy""tzz';';88@"b=113A6226::V\\*$2L2LV2T..v66
 ++F3F#||BB6==QGW"7+-@-IIIrY   c                    | j                   j                  |j                         }| j                  j                  |j                        }t        j                  ||k(  |d      }|S )zZ
        _get_indexer specialized to the case where both of our sides are unique.
        r   )r   r   r   rO   r   )r   r   left_indexerright_indexerr   s        rW   r   z'IntervalIndex._get_indexer_unique_sides  sP     yy,,V[[9

..v||<((<=8,KrY   c                   g g }}t        |      D ]  \  }}	 | j                  |      }t        |t              r8t	        j
                  |j                  |j                  |j                  d      }nEt        j                  |      rt	        j                  |d      }nt	        j                  |      d   }|j                  |        t	        j                   |      }t#        |      t#        |      fS # t        $ r* |j                  |       t	        j                  dg      }Y pt        $ r* |j                  |       t	        j                  dg      }Y w xY w)zV
        pointwise implementation for get_indexer and get_indexer_non_unique.
        intprF   rH   )ndminr   r   )	enumerater   rM   r   rO   aranger   r   r   r	   r   r   r   r   appendr   concatenater   )r   r   r   r   ir   locss          rW   r   z$IntervalIndex._get_indexer_pointwise  s    r' 	!FAs&||C(dE*99TZZDIIVTD^^D)88D2D 88D>!,D NN4 )	!, ..)"7+-@-III  &q!xx~$ & q!xx~	&s   BC330E%/EEc                R    | j                    xr | j                  j                  dk  S )N   )r   r   	_na_countr   s    rW   _index_as_uniquezIntervalIndex._index_as_unique  s%    &&&E4<<+A+AA+EErY   zKcannot handle overlapping indices; use IntervalIndex.get_indexer_non_uniquec                    |j                   <|j                   dk(  s-d}|dk(  rt        |      |dk(  rt        |      st        |      t        |   ||      S )NrH   zClabel-based slicing with step!=1 is not supported for IntervalIndexlocgetitem)r   r   r-   super_convert_slice_indexer)r   r   kindmsg	__class__s       rW   r  z$IntervalIndex._convert_slice_indexer  s\     CHHM XCu} o%y 05$S/)w-c488rY   c                F    | j                   j                  j                  dv S )NrG   )rF   r   r  r   s    rW   _should_fallback_to_positionalz,IntervalIndex._should_fallback_to_positional,  s     zz!!&&$..rY   c                :    t        | |      j                  ||      S N)rK   _maybe_cast_slice_bound)r   rV   r   s      rW   r  z%IntervalIndex._maybe_cast_slice_bound4  s    tT"::5$GGrY   c                j    t        |t              syt        | j                  |g      }t	        |       S )NF)rM   r&   r   rF   r!   )r   rF   common_subtypes      rW   _is_comparable_dtypez"IntervalIndex._is_comparable_dtype7  s0    %/)4::u*=>">222rY   c                D    t        | j                  j                  d      S NF)r|   )r.   ry   r   r   s    rW   r   zIntervalIndex.left?  s    TZZ__511rY   c                D    t        | j                  j                  d      S r  )r.   ry   r   r   s    rW   r   zIntervalIndex.rightC  s    TZZ%%E22rY   c                D    t        | j                  j                  d      S r  )r.   ry   midr   s    rW   r  zIntervalIndex.midG  s    TZZ^^%00rY   c                D    t        | j                  j                  d      S r  )r.   ry   lengthr   s    rW   r  zIntervalIndex.lengthK  s    TZZ&&U33rY   c                   | j                   j                  r(| j                  j                  r| j                  |      }np|j                   j                  rI|j                  j                  r3| j	                         j                         dk  r|j                  |       }n| j                  |      }||j                         }|S )zL
        intersection specialized to the case with matching dtypes.
        rH   )r   r   r   _intersection_uniquer   r   _intersection_non_uniquesort_values)r   othersorttakens       rW   _intersectionzIntervalIndex._intersectionR  s    
 994::#7#7--e4EZZ!!ekk&;&;		@QUV@V ..t4E 11%8E<%%'ErY   c                (   | j                   j                  |j                         }| j                  j                  |j                        }||k(  |dk7  z  }|j                  |j	                         d         }t        |      }| j                  |      S )a'  
        Used when the IntervalIndex does not have any common endpoint,
        no matter left or right.
        Return the intersection with another IntervalIndex.
        Parameters
        ----------
        other : IntervalIndex
        Returns
        -------
        IntervalIndex
        r   r   )r   r   r   taker   r)   )r   r"  lindexerrindexermatchr   s         rW   r  z"IntervalIndex._intersection_uniquef  sx     99((4::))%++6X%(b.9-- 23/yy!!rY   c                   t        j                  t        |       t              }| j                  rC|j                  r7t        j
                  t        |             | j                            d   }d||<   t        t        |j                  |j                              }t        t        | j                  | j                              D ]  \  }}||v sd||<    | |   S )a  
        Used when the IntervalIndex does have some common endpoints,
        on either sides.
        Return the intersection with another IntervalIndex.

        Parameters
        ----------
        other : IntervalIndex

        Returns
        -------
        IntervalIndex
        r   r   T)rO   zerosr   rx   r   r   r   r   zipr   r   r   )r   r"  r   first_nan_loc
other_tupsr  tups          rW   r   z&IntervalIndex._intersection_non_unique|  s      xxD	.<<EMMIIc$i0=a@M"&DUZZ56
DIItzz :; 	FAsj Q	 DzrY   c                    t        d      )NzRIntervalIndex does not use libjoin fastpaths or pass values to IndexEngine objectsr   r   s    rW   _get_engine_targetz IntervalIndex._get_engine_target  s     ""
 	
rY   c                    t        d      )Nz,IntervalIndex does not use libjoin fastpathsr2  )r   results     rW   _from_join_targetzIntervalIndex._from_join_target  s    !"PQQrY   )NNFNT)rt   IntervalClosedType | NonerF   Dtype | Noner|   rx   rC   Hashable | Noner}   rx   returnr=   )r   NFN)
rt   r7  rC   r9  r|   rx   rF   r8  r:  r?   )
rt   r<   rC   r9  r|   rx   rF   r8  r:  r?   )r:  r   )r   r   r:  rx   )r   r   r:  r?   )r:  r6   )r:  str)F)r   rx   r:  intr:  rx   )r   )r   zLiteral['left', 'right'])r:  zint | slice | np.ndarray)NNN)
r   r.   r   z
str | Noner   z
int | Noner   z
Any | Noner:  npt.NDArray[np.intp])r   r.   r:  z1tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]])r   r?   r:  r>  )r   r   r  zLiteral['loc', 'getitem'])r   r;  )rF   r;   r:  rx   )r:  r.   )r"  r?   r:  r?   )r:  z
np.ndarray)9r~   
__module____qualname___typ__annotations___can_hold_stringsr+   	_data_clsr   classmethodr   r,   textwrapdedentr   r^   r   r   r   r   r   r   r   propertyr   r.   r   __doc__r   r   r   r   r   r   r   r   r/   _index_doc_kwargsr   r   r   r  _requires_unique_msgr  r  r  r  r   r   r  r  r%  r  r   r3  r6  __classcell__)r  s   @rW   r?   r?      s   Z D "&&OI -1" $!%, *, 	,
 , , , 
,, m,$#HOO:
 (
	
. -4 $"1 *1 	1
 1 1 
1) *1 m,$#HOO:
 (
	
0 &- $"1 #	1
 1 1 1 
1) *1 m,$#HOO:
 (
	
. &- $"
/ #
/ 	
/
 
/ 
/ 

/) *
/ = =2< X X9  
 e  (()V *V 2 2  . /+ /+b)2@D<:AL "  $,, , 	,
 , 
,4  !9:=NNOJJ	:J PJ<
JJ	:J@ F F 	V 9 / /H3 2 2 3 3 1 1 4 4(",>
RrY   c                n    t        t        |       t        | t              t        | t              | du g      S )zJ
    Helper for interval_range to check if start/end are valid types.
    N)anyr    rM   r   r   )endpoints    rW   _is_valid_endpointrP    s:     hx+x+		
 rY   c                    d }d }t        |       xr t        |      xs>  ||       xr  ||      xs*  ||       xr  ||      xs t        j                  | |      S )zK
    Helper for interval_range to check type compat of start/end/freq.
    c                .    t        | t        t        f      S r  )rM   r   r   xs    rW   <lambda>z%_is_type_compatible.<locals>.<lambda>      ZIz+BC rY   c                .    t        | t        t        f      S r  )rM   r   r   rS  s    rW   rU  z%_is_type_compatible.<locals>.<lambda>  rV  rY   )r    comany_none)abis_ts_compatis_td_compats       rW   _is_type_compatibler^    sc     DLCL	1	&)A, 	O/Q	O/Q	 <<1	rY   c                l   t        |       } t        |      }| | n|}|&t        j                  || |      rt        |      rdnd}t        j                  | |||      dk7  rt        d      t        |       st        d|        t        |      st        d|       t        |      }|t        |      s	 t        |      }t        t        | |      t        | |      t        ||      g      st        d	      ||dz  }t        |      rt        j                  | ||      rt        j                  | ||d
z  z   |      }nI|t        || z
  |z        dz   }n| ||dz
  |z  z
  } n|| |dz
  |z  z   }t        j                   | ||      }t        d t        j"                  | ||      D              rOt%        |t        j&                  d            }n/t)        |t*              rt-        | |||      }nt/        | |||      }t0        j3                  |||      S # t
        $ r}t        d|       |d}~ww xY w)a  
    Return a fixed frequency IntervalIndex.

    Parameters
    ----------
    start : numeric or datetime-like, default None
        Left bound for generating intervals.
    end : numeric or datetime-like, default None
        Right bound for generating intervals.
    periods : int, default None
        Number of periods to generate.
    freq : numeric, str, Timedelta, datetime.timedelta, or DateOffset, default None
        The length of each interval. Must be consistent with the type of start
        and end, e.g. 2 for numeric, or '5H' for datetime-like.  Default is 1
        for numeric and 'D' for datetime-like.
    name : str, default None
        Name of the resulting IntervalIndex.
    closed : {'left', 'right', 'both', 'neither'}, default 'right'
        Whether the intervals are closed on the left-side, right-side, both
        or neither.

    Returns
    -------
    IntervalIndex

    See Also
    --------
    IntervalIndex : An Index of intervals that are all closed on the same side.

    Notes
    -----
    Of the four parameters ``start``, ``end``, ``periods``, and ``freq``,
    exactly three must be specified. If ``freq`` is omitted, the resulting
    ``IntervalIndex`` will have ``periods`` linearly spaced elements between
    ``start`` and ``end``, inclusively.

    To learn more about datetime-like frequency strings, please see `this link
    <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__.

    Examples
    --------
    Numeric ``start`` and  ``end`` is supported.

    >>> pd.interval_range(start=0, end=5)
    IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]],
                  dtype='interval[int64, right]')

    Additionally, datetime-like input is also supported.

    >>> pd.interval_range(start=pd.Timestamp('2017-01-01'),
    ...                   end=pd.Timestamp('2017-01-04'))
    IntervalIndex([(2017-01-01 00:00:00, 2017-01-02 00:00:00],
                   (2017-01-02 00:00:00, 2017-01-03 00:00:00],
                   (2017-01-03 00:00:00, 2017-01-04 00:00:00]],
                  dtype='interval[datetime64[ns], right]')

    The ``freq`` parameter specifies the frequency between the left and right.
    endpoints of the individual intervals within the ``IntervalIndex``.  For
    numeric ``start`` and ``end``, the frequency must also be numeric.

    >>> pd.interval_range(start=0, periods=4, freq=1.5)
    IntervalIndex([(0.0, 1.5], (1.5, 3.0], (3.0, 4.5], (4.5, 6.0]],
                  dtype='interval[float64, right]')

    Similarly, for datetime-like ``start`` and ``end``, the frequency must be
    convertible to a DateOffset.

    >>> pd.interval_range(start=pd.Timestamp('2017-01-01'),
    ...                   periods=3, freq='MS')
    IntervalIndex([(2017-01-01 00:00:00, 2017-02-01 00:00:00],
                   (2017-02-01 00:00:00, 2017-03-01 00:00:00],
                   (2017-03-01 00:00:00, 2017-04-01 00:00:00]],
                  dtype='interval[datetime64[ns], right]')

    Specify ``start``, ``end``, and ``periods``; the frequency is generated
    automatically (linearly spaced).

    >>> pd.interval_range(start=0, end=6, periods=4)
    IntervalIndex([(0.0, 1.5], (1.5, 3.0], (3.0, 4.5], (4.5, 6.0]],
              dtype='interval[float64, right]')

    The ``closed`` parameter specifies which endpoints of the individual
    intervals within the ``IntervalIndex`` are closed.

    >>> pd.interval_range(end=5, periods=4, closed='both')
    IntervalIndex([[1, 2], [2, 3], [3, 4], [4, 5]],
                  dtype='interval[int64, both]')
    NrH   D   zVOf the four parameters: start, end, periods, and freq, exactly three must be specifiedz,start must be numeric or datetime-like, got z*end must be numeric or datetime-like, got z7freq must be numeric or convertible to DateOffset, got z+start, end, freq need to be type compatibleg?c              3  2   K   | ]  }t        |        y wr  )r   ).0rT  s     rW   	<genexpr>z!interval_range.<locals>.<genexpr>`  s     Ez!}Es   int64)r   endperiodsfreq)rC   rt   )r   rX  rY  r    count_not_noner   rP  r*   r   allr^  rS   all_not_nonerO   r   r<  linspacenot_noner   rF   rM   r   r3   r8   r?   r   )	r   rf  rg  rh  rC   rt   rO  r   r   s	            rW   interval_rangern    sZ   @ #5)E
 
%C)usH|WeS9h'qS
%gt494
 	

 e$GwOPPc"EcUKLLw'G	$	T?D s+t,T*	
 EFF 1 E3-YYucTCZ&8$?F sU{t34q8w{d22w{d22[[W5FEcll5#t&DEE ,!F h	*egDQF$5c7QUVF$$V$v$FFi  	I$P	s   6H 	H3H..H3r=  )NNNNNr   )rC   r9  rt   r<   r:  r?   )irI  
__future__r   operatorr   r   rF  typingr   r   r   numpyrO   pandas._libsr	   pandas._libs.intervalr
   r   r   pandas._libs.tslibsr   r   r   r   r   pandas.errorsr   pandas.util._decoratorsr   r   pandas.util._exceptionsr   pandas.core.dtypes.castr   r   r   r   r   pandas.core.dtypes.commonr   r   r   r   r   r    r!   r"   r#   r$   pandas.core.dtypes.dtypesr%   r&   pandas.core.dtypes.missingr'   pandas.core.algorithmsr)   pandas.core.arrays.datetimeliker*   pandas.core.arrays.intervalr+   r,   pandas.core.commoncorecommonrX  pandas.core.indexersr-   pandas.core.indexes.baseindexesbaseibaser.   r/   r0   r1   pandas.core.indexes.datetimesr2   r3   pandas.core.indexes.extensionr4   r5   pandas.core.indexes.multir6   pandas.core.indexes.timedeltasr7   r8   collections.abcr9   pandas._typingr:   r;   r<   r=   r>   dictrJ  updaterG  rX   r[   ra   r?   rP  r^  rn  r]   rY   rW   <module>r     s     "     
  , 6    = ) < !   : ( (  1
 (  001     #<
	
U"U"  
'" S!&)6#HOO
: k*ME	  .9=PTUYRN YR V F;XYR| 	 !(kG
 kG kG kGrY   