HOME


sh-3ll 1.0
DIR:/usr/local/lib64/python3.6/site-packages/pandas/core/arrays/__pycache__/
Upload File :
Current File : //usr/local/lib64/python3.6/site-packages/pandas/core/arrays/__pycache__/interval.cpython-36.pyc
3

���ho��@s�ddlmZmZddlZddlZddlmZddlm	Z	m
Z
mZddlm
ZddlmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZdd	l m!Z!dd
l"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)m*Z*ddl+m,Z,m-Z-dd
l.m/Z/m0Z0ddl1m2Z2ddl3j4j5Z6ddl7m8Z8ddl9m:Z:ddl;m<Z<ddddhZ=iZ>e?dddd�Z@de>d<ee>de?ddddddejAd�d��Gd d�de
e/��ZBd!d"�ZCdS)#�)�le�ltN)�
get_option)�Interval�
IntervalMixin�intervals_to_interval_bounds)�function)�Appender)�maybe_convert_platform)�is_categorical_dtype�is_datetime64_any_dtype�is_float_dtype�is_integer_dtype�is_interval�is_interval_dtype�is_list_like�is_object_dtype�	is_scalar�is_string_dtype�is_timedelta64_dtype�pandas_dtype)�
IntervalDtype)�ABCDatetimeIndex�
ABCIndexClass�ABCIntervalIndex�ABCPeriodIndex�	ABCSeries)�isna�notna)�take�value_counts)�ExtensionArray�_extension_array_shared_docs)�Categorical)�array)�check_array_indexer)�ensure_index�left�right�bothZneither�
IntervalArrayzarrays.IntervalArray�)�klass�qualname�namea�
%(summary)s

.. versionadded:: %(versionadded)s

Parameters
----------
data : array-like (1-dimensional)
    Array-like containing Interval objects from which to build the
    %(klass)s.
closed : {'left', 'right', 'both', 'neither'}, default 'right'
    Whether the intervals are closed on the left-side, right-side, both or
    neither.
dtype : dtype or None, default None
    If None, dtype will be inferred.

    .. versionadded:: 0.23.0
copy : bool, default False
    Copy the input data.
%(name)sverify_integrity : bool, default True
    Verify that the %(klass)s is valid.

Attributes
----------
left
right
closed
mid
length
is_empty
is_non_overlapping_monotonic
%(extra_attributes)s
Methods
-------
from_arrays
from_tuples
from_breaks
contains
overlaps
set_closed
to_tuples
%(extra_methods)s
See Also
--------
Index : The base pandas Index type.
Interval : A bounded slice-like interval; the elements of an %(klass)s.
interval_range : Function to create a fixed frequency IntervalIndex.
cut : Bin values into discrete Intervals.
qcut : Bin values into equal-sized Intervals based on rank or sample quantiles.

Notes
-----
See the `user guide
<https://pandas.pydata.org/pandas-docs/stable/user_guide/advanced.html#intervalindex>`_
for more.

%(examples)s�classz@Pandas array for interval data that are closed on the same side.z0.24.0a�    Examples
    --------
    A new ``IntervalArray`` can be constructed directly from an array-like of
    ``Interval`` objects:

    >>> pd.arrays.IntervalArray([pd.Interval(0, 1), pd.Interval(1, 5)])
    <IntervalArray>
    [(0, 1], (1, 5]]
    Length: 2, closed: right, dtype: interval[int64]

    It may also be constructed using one of the constructor
    methods: :meth:`IntervalArray.from_arrays`,
    :meth:`IntervalArray.from_breaks`, and :meth:`IntervalArray.from_tuples`.
    )r,�summaryZversionaddedr.Zextra_attributesZ
extra_methods�examplesc@sFeZdZdZdZejZZdve	e	d�dd�Z
edwdd	��Zedxd
d��Z
edd
��Zejd�ed<eeededejd�d��dydd���Zejd�ed<eeededejd�d��dzdd���Zejd�ed<eeededejd�d��d{dd���Zdd �Zd!d"�Zed#�d$d%�Zd&d'�Zd(d)�Zd*d+�Zd|d,d-�Zed.d/��Z d}d0d1�Z!ed2d3��Z"d4d5�Z#d6d7�Z$d8d9�Z%eed#�d:d;��Z&eed#�d<d=��Z'd~ee(dd>�d?d@�Z)ddAdB�Z*d�dCdD�Z+dEdF�Z,e-d#�dGdH�Z.dIdJ�Z/edKdL��Z0edMdN��Z1edOdP��Z2ejdQ�edR<eedRedejdS�d��dTdU��Z3edVdW��Z4edXdY��Z5dZed[<eeed[e6�d\d]���Z7d�ej8d#�d^d_�Z9d�d`da�Z:dbedc<eedcedddedf��d�dgdh��Z;ee<die6�d�djdk��Z=ejdl�edm<eedmedejdn�d��dodp��Z>ejdq�edr<eedredejds�d��dtdu��Z?dS)�r*�TNF)�copy�verify_integrityc
Cs�t|t�rt|j�r|j}t||tf�r@|j}|j}|p<|j}nHt	|�rb|j
�d|�d�}t|��t|�}t
||dkd�\}}}	|p�|	}|j||||||d�S)Nz5(...) must be called with a collection of some kind, z was passed)Zvalidate_closed)r3�dtyper4)�
isinstancerrr5�_valuesrr'r(�closedr�__name__�	TypeError�maybe_convert_platform_intervalr�_simple_new)
�cls�datar8r5r3r4r'r(�msgZinfer_closed�r@�=/tmp/pip-build-5_djhm0z/pandas/pandas/core/arrays/interval.py�__new__�s(	zIntervalArray.__new__c	Cs�tj|�}|pd}t||d�}t||d�}|dk	rxt|�}t|�sVd|��}t|��n"|jdk	rx|j|j�}|j|j�}t|�r�t	|�r�|j|j
�}nt|�r�t	|�r�|j|j
�}t|�t|�kr�dt|�j�dt|�j�d�}t
|��n~t|j
�p�t|j
��rd}t|��nZt|t��r(d}t
|��n@t|t��rht|j�t|j�k�rhd	|j�d
|j�d�}t
|��||_||_||_|�r�|j�|S)Nr()r3z$dtype must be an IntervalDtype, got zmust not have differing left [z
] and right [z] typeszIcategory, object, and string subtypes are not supported for IntervalArrayz:Period dtypes are not supported, use a PeriodIndex insteadz2left and right must have the same time zone, got 'z' and '�')rrBr&rrr:�subtype�astyper
rr5�typer9�
ValueErrorrrr6rr�str�tz�_left�_right�_closed�	_validate)	r=r'r(r8r3r5r4�resultr?r@r@rAr<�sD






"zIntervalArray._simple_newcCs||||d�S)N)r5r3r@)r=Zscalarsr5r3r@r@rA�_from_sequence�szIntervalArray._from_sequencecCs(t|�dkr|j|jj�}|||jd�S)Nr)r8)�lenrEr5rDr8)r=�values�originalr@r@rA�_from_factorized�szIntervalArray._from_factorizeda
    Construct an %(klass)s from an array of splits.

    Parameters
    ----------
    breaks : array-like (1-dimensional)
        Left and right bounds for each interval.
    closed : {'left', 'right', 'both', 'neither'}, default 'right'
        Whether the intervals are closed on the left-side, right-side, both
        or neither.
    copy : bool, default False
        Copy the data.
    dtype : dtype or None, default None
        If None, dtype will be inferred.

        .. versionadded:: 0.23.0

    Returns
    -------
    %(klass)s

    See Also
    --------
    interval_range : Function to create a fixed frequency IntervalIndex.
    %(klass)s.from_arrays : Construct from a left and right array.
    %(klass)s.from_tuples : Construct from a sequence of tuples.

    %(examples)s    �from_breaksz�        Examples
        --------
        >>> pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3])
        <IntervalArray>
        [(0, 1], (1, 2], (2, 3]]
        Length: 3, closed: right, dtype: interval[int64]
        )r,r1r(cCs,t|�}|j|dd�|dd�|||d�S)Nr2)r3r5���)r;�from_arrays)r=Zbreaksr8r3r5r@r@rArT&szIntervalArray.from_breaksaY
        Construct from two arrays defining the left and right bounds.

        Parameters
        ----------
        left : array-like (1-dimensional)
            Left bounds for each interval.
        right : array-like (1-dimensional)
            Right bounds for each interval.
        closed : {'left', 'right', 'both', 'neither'}, default 'right'
            Whether the intervals are closed on the left-side, right-side, both
            or neither.
        copy : bool, default False
            Copy the data.
        dtype : dtype, optional
            If None, dtype will be inferred.

            .. versionadded:: 0.23.0

        Returns
        -------
        %(klass)s

        Raises
        ------
        ValueError
            When a value is missing in only one of `left` or `right`.
            When a value in `left` is greater than the corresponding value
            in `right`.

        See Also
        --------
        interval_range : Function to create a fixed frequency IntervalIndex.
        %(klass)s.from_breaks : Construct an %(klass)s from an array of
            splits.
        %(klass)s.from_tuples : Construct an %(klass)s from an
            array-like of tuples.

        Notes
        -----
        Each element of `left` must be less than or equal to the `right`
        element at the same position. If an element is missing, it must be
        missing in both `left` and `right`. A TypeError is raised when
        using an unsupported type for `left` or `right`. At the moment,
        'category', 'object', and 'string' subtypes are not supported.

        %(examples)s        rVz�        >>> pd.arrays.IntervalArray.from_arrays([0, 1, 2], [1, 2, 3])
        <IntervalArray>
        [(0, 1], (1, 2], (2, 3]]
        Length: 3, closed: right, dtype: interval[int64]
        cCs&t|�}t|�}|j|||||dd�S)NT)r3r5r4)r;r<)r=r'r(r8r3r5r@r@rArVoszIntervalArray.from_arraysa�
    Construct an %(klass)s from an array-like of tuples.

    Parameters
    ----------
    data : array-like (1-dimensional)
        Array of tuples.
    closed : {'left', 'right', 'both', 'neither'}, default 'right'
        Whether the intervals are closed on the left-side, right-side, both
        or neither.
    copy : bool, default False
        By-default copy the data, this is compat only and ignored.
    dtype : dtype or None, default None
        If None, dtype will be inferred.

        .. versionadded:: 0.23.0

    Returns
    -------
    %(klass)s

    See Also
    --------
    interval_range : Function to create a fixed frequency IntervalIndex.
    %(klass)s.from_arrays : Construct an %(klass)s from a left and
                                right array.
    %(klass)s.from_breaks : Construct an %(klass)s from an array of
                                splits.

    %(examples)s    �from_tuplesz�        Examples
        --------
        >>> pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 2)])
        <IntervalArray>
        [(0, 1], (1, 2]]
        Length: 2, closed: right, dtype: interval[int64]
        c
Cs�t|�rgg}}n|}}x�|D]�}t|�r:tj}}	n�|j}
y|\}}	Wnrtk
r�}z|
�d|��}t|�|�WYdd}~Xn:tk
r�}z|
�d|��}t|�|�WYdd}~XnX|j|�|j|	�q"W|j|||d|d�S)Nz..from_tuples requires tuples of length 2, got z'.from_tuples received an invalid item, F)r3r5)	rPr�np�nanr9rGr:�appendrV)
r=r>r8r3r5r'r(�d�lhs�rhsr.�errr?r@r@rArW�s$

zIntervalArray.from_tuplescCs�|jtkrd|j��}t|��t|j�t|j�kr>d}t|��t|j�}t|j�}||kj�sjd}t|��|j||j|kj�s�d}t|��dS)z�
        Verify that the IntervalArray is valid.

        Checks that

        * closed is valid
        * left and right match lengths
        * left and right have the same missing values
        * left is always below right
        zinvalid option for 'closed': z(left and right must have the same lengthzMmissing values must be missing in the same location both left and right sidesz+left side of interval must be <= right sideN)r8�
_VALID_CLOSEDrGrPr'r(r�all)�selfr?Z	left_maskZ
right_maskr@r@rArM�s


zIntervalArray._validatecCsttj|��S)N)�iterrX�asarray)rar@r@rA�__iter__�szIntervalArray.__iter__)�returncCs
t|j�S)N)rPr')rar@r@rA�__len__�szIntervalArray.__len__cCsnt||�}|j|}|j|}t|t�sbt|�r>t|�r>|jStj	|�dkrTt
d��t|||j�S|j
||�S)Nr2z&multi-dimensional indexing not allowed)r%r'r(r6rrr�_fill_valuerX�ndimrGrr8�
_shallow_copy)ra�valuer'r(r@r@rA�__getitem__�s



zIntervalArray.__getitem__cCs>d}t|�r`t|�r`t|jj�r&d}n.t|jj�r>tjd�}nt|jj�rTtj	d�}||}}n�t
|�srt|t�r�|j
|dd�|j|j}}nXyt|�}|j|j}}Wn<tk
r�}z dt|��d�}t|�|�WYdd}~XnX|r�td��t||�}|jjdd	�}	||	j|<|	|_|jjdd	�}
||
j|<|
|_dS)
NFTZNaTrj)r.z('value' should be an interval type, got z	 instead.z4Cannot set float NaN to integer-backed IntervalArray)�deep)rrrr5rDrrXZ
datetime64rZtimedelta64rr6r�_check_closed_matchesr'r(r*r:rFrGr%r3r7rJrK)ra�keyrjZneeds_float_conversionZ
value_leftZvalue_rightr$r^r?r'r(r@r@rA�__setitem__	s6



zIntervalArray.__setitem__cCsxt|�r*t|�t|�kr td��t|�}nt|t�sFtjt|�td�St|t�rZt	d�}nPt
|j�sl|j}n>|jj}t
|�r�|j|jjkr�tjt|�td�S|jj|j�}t
|�r�|j|jkr�tjt|�td�S|j|jk|j|jk@St|��stjt|�td�Stjt|�td�}x\t|�D]P\}}t|t��r |j|jk�r |j||jk�r |j||jk�r d||<�q W|S)NzLengths must match to compare)r5�intervalT)rrPrGr$r6rrX�zeros�boolrrr5�
categoriesrr8r�codesr'r(r�	enumerate)ra�otherZother_dtyperN�i�objr@r@rA�__eq__6s:





zIntervalArray.__eq__cCs~|dk	rtd��|dk	r td��t|t�sDdt|�j�d�}t|��|j|dd�|jj|jd�}|jj|jd�}|j	||�S)	a�
        Fill NA/NaN values using the specified method.

        Parameters
        ----------
        value : scalar, dict, Series
            If a scalar value is passed it is used to fill all missing values.
            Alternatively, a Series or dict can be used to fill in different
            values for each index. The value should not be a list. The
            value(s) passed should be either Interval objects or NA/NaN.
        method : {'backfill', 'bfill', 'pad', 'ffill', None}, default None
            (Not implemented yet for IntervalArray)
            Method to use for filling holes in reindexed Series
        limit : int, default None
            (Not implemented yet for IntervalArray)
            If method is specified, this is the maximum number of consecutive
            NaN values to forward/backward fill. In other words, if there is
            a gap with more than this number of consecutive NaNs, it will only
            be partially filled. If method is not specified, this is the
            maximum number of entries along the entire axis where NaNs will be
            filled.

        Returns
        -------
        filled : IntervalArray with NA/NaN filled
        Nz5Filling by method is not supported for IntervalArray.z)limit is not supported for IntervalArray.zU'IntervalArray.fillna' only supports filling with a scalar 'pandas.Interval'. Got a 'z
' instead.rj)r.)rj)
r:r6rrFr9rmr'�fillnar(ri)rarj�method�limitr?r'r(r@r@rArzgs
zIntervalArray.fillnacCst|jj�S)N)rr'r5)rar@r@rAr5�szIntervalArray.dtypecCs@ddlm}|dk	rt|�}t|�r�||jkr>|r:|j�S|Sy |jj|j�}|j	j|j�}Wn@t
k
r�}z$d|j�d|�d�}t
|�|�WYdd}~XnX|j||�St|�r�t
tj|��St||�r�|j�j|dd�Sytj|�j||d�St
tfk
�r:}z&d	t|�j�d
|��}t
|�|�WYdd}~XnXdS)a(
        Cast to an ExtensionArray or NumPy array with dtype 'dtype'.

        Parameters
        ----------
        dtype : str or dtype
            Typecode or data-type to which the array is cast.

        copy : bool, default True
            Whether to copy the data, even if not necessary. If False,
            a copy is made only if the old dtype does not match the
            new dtype.

        Returns
        -------
        array : ExtensionArray or ndarray
            ExtensionArray or NumPy ndarray with 'dtype' for its dtype.
        r)�StringDtypeNzCannot convert z to z; subtypes are incompatibleF)r3zCannot cast z
 to dtype )Zpandas.core.arrays.string_r}rrr5r3r'rErDr(r:rirr#rXrcr6Zconstruct_array_typerOrGrFr9)rar5r3r}Znew_leftZ	new_rightr^r?r@r@rArE�s,

zIntervalArray.astypecCsddd�|D�}t|�dkr"td��|j�}tjdd�|D��}tjdd�|D��}|j|||dd	�S)
z�
        Concatenate multiple IntervalArray

        Parameters
        ----------
        to_concat : sequence of IntervalArray

        Returns
        -------
        IntervalArray
        cSsh|]
}|j�qSr@)r8)�.0rpr@r@rA�	<setcomp>�sz2IntervalArray._concat_same_type.<locals>.<setcomp>r2z.Intervals must all be closed on the same side.cSsg|]
}|j�qSr@)r')r~rpr@r@rA�
<listcomp>�sz3IntervalArray._concat_same_type.<locals>.<listcomp>cSsg|]
}|j�qSr@)r()r~rpr@r@rAr��sF)r8r3)rPrG�poprXZconcatenater<)r=Z	to_concatr8r'r(r@r@rA�_concat_same_type�s
zIntervalArray._concat_same_typecCs|j|||jdd�S)a#
        Return a new IntervalArray with the replacement attributes

        Parameters
        ----------
        left : Index
            Values to be used for the left-side of the intervals.
        right : Index
            Values to be used for the right-side of the intervals.
        F)r8r4)r<r8)rar'r(r@r@rAri�szIntervalArray._shallow_copycCs6|jjdd�}|jjdd�}|j}t|�j|||d�S)zd
        Return a copy of the array.

        Returns
        -------
        IntervalArray
        T)rl)r8)r'r3r(r8rFrV)rar'r(r8r@r@rAr3�szIntervalArray.copycCs
t|j�S)N)rr')rar@r@rAr�szIntervalArray.isnacCs|jj|jjS)N)r'�nbytesr()rar@r@rAr��szIntervalArray.nbytescCs|jjS)N)r'�size)rar@r@rAr�szIntervalArray.size)�periods�
fill_valuerecCs�t|�s|dkr|j�St|�r*|jj}tt|�t|��}t|�rb|jj}t	j
|g|d�}n|j|g|�}|dkr�|}|d|�}n|t|�d�}|}|j||g�S)Nrr2)
rPr3rr5Zna_value�min�absr'�	_na_valuer*rTrOr�)rar�r�Z	empty_len�empty�a�br@r@rA�shiftszIntervalArray.shiftcKs�tjt�|�|}}|r�|dkr0|jj}}nRt|�rV|j|dd�|j|j}}n,t|�r�t	|�r�dt
|�j�d�}t|��t
|j|||d�}	t
|j|||d�}
|j|	|
�S)am
        Take elements from the IntervalArray.

        Parameters
        ----------
        indices : sequence of integers
            Indices to be taken.

        allow_fill : bool, default False
            How to handle negative values in `indices`.

            * False: negative values in `indices` indicate positional indices
              from the right (the default). This is similar to
              :func:`numpy.take`.

            * True: negative values in `indices` indicate
              missing values. These values are set to `fill_value`. Any other
              other negative values raise a ``ValueError``.

        fill_value : Interval or NA, optional
            Fill value to use for NA-indices when `allow_fill` is True.
            This may be ``None``, in which case the default NA value for
            the type, ``self.dtype.na_value``, is used.

            For many ExtensionArrays, there will be two representations of
            `fill_value`: a user-facing "boxed" scalar, and a low-level
            physical NA value. `fill_value` should be the user-facing version,
            and the implementation should handle translating that to the
            physical version for processing the take if necessary.

        axis : any, default None
            Present for compat with IntervalIndex; does nothing.

        Returns
        -------
        IntervalArray

        Raises
        ------
        IndexError
            When the indices are out of bounds for the array.
        ValueError
            When `indices` contains negative values other than ``-1``
            and `allow_fill` is True.
        Nr�)r.z['IntervalArray.fillna' only supports filling with a 'scalar pandas.Interval or NA'. Got a 'z
' instead.)�
allow_fillr�)�nvZ
validate_take�tupler'r�rrmr(rrrFr9rGrri)ra�indicesr�r��axis�kwargsZ	fill_leftZ
fill_rightr?Z	left_takeZ
right_taker@r@rAr"s .zIntervalArray.takecCsttj|�|d�S)a2
        Returns a Series containing counts of each interval.

        Parameters
        ----------
        dropna : bool, default True
            Don't include counts of NaN.

        Returns
        -------
        counts : Series

        See Also
        --------
        Series.value_counts
        )�dropna)r rXrc)rar�r@r@rAr jszIntervalArray.value_countsc
s&t|�}ttd�p|dd�}t�|dkr0d}n�|dkrR�|d�}d|�d�}n�|dkr��|d�}�|d�}d|�d	|�d�}n�||kr�t|dd�}�fd
d�|d|�D�}�fdd�||d�D�}d	j|�}d	j|�}	d|�d
|	�d�}n(�fdd�|D�}d	j|�}	d|	�d�}|S)Nzdisplay.max_seq_items�
rz[]r2�[�]�z, csg|]}�|��qSr@r@)r~�x)�	formatterr@rAr��sz.IntervalArray._format_data.<locals>.<listcomp>csg|]}�|��qSr@r@)r~r�)r�r@rAr��sz ... csg|]}�|��qSr@r@)r~r�)r�r@rAr��srU)rPr�rrH�join)
ra�nZ
max_seq_itemsr0�first�last�head�tailZhead_strZtail_strr@)r�rA�_format_data�s.


zIntervalArray._format_datacCsD|j�}dt|�j�d�}|�|�dt|��d|j�d|j��}|S)N�<z>
z	
Length: z
, closed: z	, dtype: )r�rFr9rPr8r5)rar>�
class_name�templater@r@rA�__repr__�s&zIntervalArray.__repr__cCs dtt|�j�d}d|��S)N� r2�
)rPrFr9)ra�spacer@r@rA�
_format_space�szIntervalArray._format_spacecCs|jS)zf
        Return the left endpoints of each Interval in the IntervalArray as
        an Index.
        )rJ)rar@r@rAr'�szIntervalArray.leftcCs|jS)zg
        Return the right endpoints of each Interval in the IntervalArray as
        an Index.
        )rK)rar@r@rAr(�szIntervalArray.rightcCs|jS)zi
        Whether the intervals are closed on the left-side, right-side, both or
        neither.
        )rL)rar@r@rAr8�szIntervalArray.closeda�
        Return an %(klass)s identical to the current one, but closed on the
        specified side.

        .. versionadded:: 0.24.0

        Parameters
        ----------
        closed : {'left', 'right', 'both', 'neither'}
            Whether the intervals are closed on the left-side, right-side, both
            or neither.

        Returns
        -------
        new_index : %(klass)s

        %(examples)s        �
set_closeda�        Examples
        --------
        >>> index = pd.arrays.IntervalArray.from_breaks(range(4))
        >>> index
        <IntervalArray>
        [(0, 1], (1, 2], (2, 3]]
        Length: 3, closed: right, dtype: interval[int64]
        >>> index.set_closed('both')
        <IntervalArray>
        [[0, 1], [1, 2], [2, 3]]
        Length: 3, closed: both, dtype: interval[int64]
        cCs4|tkrd|��}t|��t|�j|j|j|dd�S)Nzinvalid option for 'closed': F)r'r(r8r4)r_rGrFr<r'r()rar8r?r@r@rAr��s

zIntervalArray.set_closedcCsBy|j|jStk
r<}zd}t|�|�WYdd}~XnXdS)zq
        Return an Index with entries denoting the length of each Interval in
        the IntervalArray.
        z]IntervalArray contains Intervals without defined length, e.g. Intervals with string endpointsN)r(r'r:)rar^r?r@r@rA�length�s
zIntervalArray.lengthcCs6yd|j|jStk
r0|jd|jSXdS)zX
        Return the midpoint of each Interval in the IntervalArray as an Index.
        g�?N)r'r(r:r�)rar@r@rA�midszIntervalArray.midz�
        Return True if the %(klass)s is non-overlapping (no Intervals share
        points) and is either monotonic increasing or monotonic decreasing,
        else False.
        �is_non_overlapping_monotoniccCs�|jdkrNt|jdd�|jdd�kj�pJ|jdd�|jdd�kj��St|jdd�|jdd�kj�p�|jdd�|jdd�kj��S)Nr)r2rUrUrUrU)r8rrr(r'r`)rar@r@rAr�$s
 " z*IntervalArray.is_non_overlapping_monotoniccCsr|j}|j}|j�}|j}tjt|�td�}x@tt|��D]0}||rRtj	||<q:t
|||||�||<q:W|S)zt
        Return the IntervalArray's data as a numpy array of Interval
        objects (with dtype='object')
        )r5)r'r(rrLrXr�rP�object�rangerYr)rar5r'r(�maskr8rNrwr@r@rA�	__array__=szIntervalArray.__array__c
Cspddl}ddlm}y|j|jj�}Wn8tk
r^}ztd|jj�d��|�WYdd}~XnX|||j�}|jj	|j
|j|dd�|j
|j|dd�gdd	gd
�}|j
�}|j�r�|j
|�j�d}	|jj|jt|�|	g|jd�|jd�gd�}|dk	�rb|j|j��r|St||��rR|j|��sbtd
|jj�d|j�d|j�d|j�d�	��ntd|�d���|jj||�S)z6
        Convert myself into a pyarrow Array.
        rN)�ArrowIntervalTypez"Conversion to arrow with subtype 'z' is not supportedT)rFZfrom_pandasr'r()�namesr2)�childrenzINot supported to convert IntervalArray to type with different 'subtype' (z vs z) and 'closed' (z) attributesz+Not supported to convert IntervalArray to 'z' type)�pyarrowZpandas.core.arrays._arrow_utilsr�Zfrom_numpy_dtyper5rDr:r8ZStructArrayrVr$r'r(r�any�buffersZfrom_buffersrFrP�field�equalsZstorage_typer6r!Zfrom_storage)
rarFr�r�rDr^Z
interval_typeZ
storage_arrayr�Znull_bitmapr@r@rA�__arrow_array__Os>
,zIntervalArray.__arrow_array__a�
        Return an %(return_type)s of tuples of the form (left, right).

        Parameters
        ----------
        na_tuple : bool, default True
            Returns NA as a tuple if True, ``(nan, nan)``, or just as the NA
            value itself if False, ``nan``.

            .. versionadded:: 0.23.0

        Returns
        -------
        tuples: %(return_type)s
        %(examples)s        �	to_tuples�ndarrayr+)�return_typer1cCs2tjt|j|j��}|s.tj|j�|tj�}|S)N)	�comZasarray_tuplesafe�zipr'r(rX�whererrY)raZna_tupleZtuplesr@r@rAr��szIntervalArray.to_tuples�repeatcCs:tjt�t|d��|jj|�}|jj|�}|j||d�S)N)r�)r'r()r�Zvalidate_repeatr��dictr'r�r(ri)raZrepeatsr�Zleft_repeatZright_repeatr@r@rAr��szIntervalArray.repeata�
        Check elementwise if the Intervals contain the value.

        Return a boolean mask whether the value is contained in the Intervals
        of the %(klass)s.

        .. versionadded:: 0.25.0

        Parameters
        ----------
        other : scalar
            The value to check whether it is contained in the Intervals.

        Returns
        -------
        boolean array

        See Also
        --------
        Interval.contains : Check whether Interval object contains value.
        %(klass)s.overlaps : Check if an Interval overlaps the values in the
            %(klass)s.

        Examples
        --------
        %(examples)s
        >>> intervals.contains(0.5)
        array([ True, False, False])
    �containsz�        >>> intervals = pd.arrays.IntervalArray.from_tuples([(0, 1), (1, 3), (2, 4)])
        >>> intervals
        <IntervalArray>
        [(0, 1], (1, 3], (2, 4]]
        Length: 3, closed: right, dtype: interval[int64]
        cCsFt|t�rtd��|jr"|j|kn|j|k|jr:||jkn||jk@S)Nz*contains not implemented for two intervals)r6r�NotImplementedErrorZ	open_leftr'Z
open_rightr()rarvr@r@rAr��s
zIntervalArray.containsak
        Check elementwise if an Interval overlaps the values in the %(klass)s.

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

        .. versionadded:: 0.24.0

        Parameters
        ----------
        other : %(klass)s
            Interval to check against for an overlap.

        Returns
        -------
        ndarray
            Boolean array positionally indicating where an overlap occurs.

        See Also
        --------
        Interval.overlaps : Check whether two Interval objects overlap.

        Examples
        --------
        %(examples)s
        >>> intervals.overlaps(pd.Interval(0.5, 1.5))
        array([ True,  True, False])

        Intervals that share closed endpoints overlap:

        >>> intervals.overlaps(pd.Interval(1, 3, closed='left'))
        array([ True,  True, True])

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

        >>> intervals.overlaps(pd.Interval(1, 2, closed='right'))
        array([False,  True, False])
        �overlapsz�        >>> data = [(0, 1), (1, 3), (2, 4)]
        >>> intervals = pd.arrays.IntervalArray.from_tuples(data)
        >>> intervals
        <IntervalArray>
        [(0, 1], (1, 3], (2, 4]]
        Length: 3, closed: right, dtype: interval[int64]
        cCszt|ttf�rt�n"t|t�s6dt|�j��}t|��|jrF|j	rFt
nt}|jrZ|j	rZt
nt}||j|j
�||j|j
�@S)Nz#`other` must be Interval-like, got )r6r*rr�rrFr9r:Zclosed_leftZclosed_rightrrr'r()rarvr?Zop1Zop2r@r@rAr�s
zIntervalArray.overlaps)NNFT)NFNT)NF)r(FN)r(FN)r(FN)NNN)T)r2N)FNN)T)N)N)T)N)@r9�
__module__�__qualname__rhZcan_hold_narXrYr�rgrrrB�classmethodr<rOrS�textwrap�dedent�_interval_shared_docsr	r�rTrVrWrMrd�intrfrkroryrz�propertyr5rEr�rir3rr�r�r�r�rr r�rHr�r�r'r(r8r�r�r��_shared_docs_kwargsr�r�r�r�r�r"r�r�r�r@r@r@rAr*vs�
$6	
0

 -1
-
2

H
"



E
'
cCsDt|ttf�r*t|�dkr*tjgtjd�St|�r<tj|�}t	|�S)a�
    Try to do platform conversion, with special casing for IntervalArray.
    Wrapper around maybe_convert_platform that alters the default return
    dtype in certain cases to be compatible with IntervalArray.  For example,
    empty lists return with integer dtype instead of object dtype, which is
    prohibited for IntervalArray.

    Parameters
    ----------
    values : array-like

    Returns
    -------
    array
    r)r5)
r6�listr�rPrXr$Zint64rrcr
)rQr@r@rAr;)s

r;)D�operatorrrr�ZnumpyrXZpandas._configrZpandas._libs.intervalrrrZpandas.compat.numpyrr�Zpandas.util._decoratorsr	Zpandas.core.dtypes.castr
Zpandas.core.dtypes.commonrrr
rrrrrrrrrZpandas.core.dtypes.dtypesrZpandas.core.dtypes.genericrrrrrZpandas.core.dtypes.missingrrZpandas.core.algorithmsrr Zpandas.core.arrays.baser!r"Zpandas.core.arrays.categoricalr#Zpandas.core.common�core�commonr�Zpandas.core.constructionr$Zpandas.core.indexersr%Zpandas.core.indexes.baser&r_r�r�r�r�r*r;r@r@r@rA�<module>sZ8B