o
    _~#gf                     @  s  d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddl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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  ddl!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6 ddl7m8  m9Z: erddl;m<Z<m=Z= ddl>m?Z? 		dNdOddZ@eAh dZBe
	 dPdQd&d'ZCe
	 dPdRd*d'ZC	+dSdRd,d'ZCd-d. ZDdTd1d2ZE		+dUd+d3dVd8d9ZFdWd<d=ZGdXd?d@ZHd+d3dYdBdCZIdZdEdFZJd[dHdIZKd\dLdMZLdS )]z
Constructor functions intended to be shared by pd.array, Series.__init__,
and Index.__new__.

These should not depend on core.internals.
    )annotations)Sequence)TYPE_CHECKINGOptionalUnioncastoverloadN)ma)using_pyarrow_string_dtype)lib)Periodget_supported_dtypeis_supported_dtype)AnyArrayLike	ArrayLikeDtypeDtypeObjT)find_stack_level)ExtensionDtype)"construct_1d_arraylike_from_scalar'construct_1d_object_array_from_listlikemaybe_cast_to_datetimemaybe_cast_to_integer_arraymaybe_convert_platformmaybe_infer_to_datetimelikemaybe_promote)is_list_likeis_object_dtypeis_string_dtypepandas_dtype)NumpyEADtype)ABCDataFrameABCExtensionArrayABCIndex	ABCSeries)isna)IndexSeries)ExtensionArrayTdataSequence[object] | AnyArrayLikedtypeDtype | Nonecopyboolreturnr)   c                 C  s  ddl m}m}m}m}m}m}m}	m}
m	} ddl
m} t| r+d|  d}t|t| tr4td|du rCt| tt|frC| j}t| dd	} |durQt|}t| |rg|du s_| j|krg|re|  S | S t|trx| }|j| ||d
S |du rtj| dd}|dkrttttt   t!f | }|
j||dS |dkr|| |dS |"drz|j| |dW S  ty   Y nbw |"dr|j| |dS |dkr| }| }|j| ||d
S |dkr|j| |dS |dkrt#| dst$| s|j| |dS |dv rt%| ddt&j'kr|j| |dS |dkr|j| d|d
S t(|dr2t)|r2|j| ||d
S t(|drFt)|rF|j| ||d
S t(|drVt*j+dt,t- d |	j| ||d
S )a  
    Create an array.

    Parameters
    ----------
    data : Sequence of objects
        The scalars inside `data` should be instances of the
        scalar type for `dtype`. It's expected that `data`
        represents a 1-dimensional array of data.

        When `data` is an Index or Series, the underlying array
        will be extracted from `data`.

    dtype : str, np.dtype, or ExtensionDtype, optional
        The dtype to use for the array. This may be a NumPy
        dtype or an extension type registered with pandas using
        :meth:`pandas.api.extensions.register_extension_dtype`.

        If not specified, there are two possibilities:

        1. When `data` is a :class:`Series`, :class:`Index`, or
           :class:`ExtensionArray`, the `dtype` will be taken
           from the data.
        2. Otherwise, pandas will attempt to infer the `dtype`
           from the data.

        Note that when `data` is a NumPy array, ``data.dtype`` is
        *not* used for inferring the array type. This is because
        NumPy cannot represent all the types of data that can be
        held in extension arrays.

        Currently, pandas will infer an extension dtype for sequences of

        ============================== =======================================
        Scalar Type                    Array Type
        ============================== =======================================
        :class:`pandas.Interval`       :class:`pandas.arrays.IntervalArray`
        :class:`pandas.Period`         :class:`pandas.arrays.PeriodArray`
        :class:`datetime.datetime`     :class:`pandas.arrays.DatetimeArray`
        :class:`datetime.timedelta`    :class:`pandas.arrays.TimedeltaArray`
        :class:`int`                   :class:`pandas.arrays.IntegerArray`
        :class:`float`                 :class:`pandas.arrays.FloatingArray`
        :class:`str`                   :class:`pandas.arrays.StringArray` or
                                       :class:`pandas.arrays.ArrowStringArray`
        :class:`bool`                  :class:`pandas.arrays.BooleanArray`
        ============================== =======================================

        The ExtensionArray created when the scalar type is :class:`str` is determined by
        ``pd.options.mode.string_storage`` if the dtype is not explicitly given.

        For all other cases, NumPy's usual inference rules will be used.
    copy : bool, default True
        Whether to copy the data, even if not necessary. Depending
        on the type of `data`, creating the new array may require
        copying data, even if ``copy=False``.

    Returns
    -------
    ExtensionArray
        The newly created array.

    Raises
    ------
    ValueError
        When `data` is not 1-dimensional.

    See Also
    --------
    numpy.array : Construct a NumPy array.
    Series : Construct a pandas Series.
    Index : Construct a pandas Index.
    arrays.NumpyExtensionArray : ExtensionArray wrapping a NumPy array.
    Series.array : Extract the array stored within a Series.

    Notes
    -----
    Omitting the `dtype` argument means pandas will attempt to infer the
    best array type from the values in the data. As new array types are
    added by pandas and 3rd party libraries, the "best" array type may
    change. We recommend specifying `dtype` to ensure that

    1. the correct array type for the data is returned
    2. the returned array type doesn't change as new extension types
       are added by pandas and third-party libraries

    Additionally, if the underlying memory representation of the returned
    array matters, we recommend specifying the `dtype` as a concrete object
    rather than a string alias or allowing it to be inferred. For example,
    a future version of pandas or a 3rd-party library may include a
    dedicated ExtensionArray for string data. In this event, the following
    would no longer return a :class:`arrays.NumpyExtensionArray` backed by a
    NumPy array.

    >>> pd.array(['a', 'b'], dtype=str)
    <NumpyExtensionArray>
    ['a', 'b']
    Length: 2, dtype: str32

    This would instead return the new ExtensionArray dedicated for string
    data. If you really need the new array to be backed by a  NumPy array,
    specify that in the dtype.

    >>> pd.array(['a', 'b'], dtype=np.dtype("<U1"))
    <NumpyExtensionArray>
    ['a', 'b']
    Length: 2, dtype: str32

    Finally, Pandas has arrays that mostly overlap with NumPy

      * :class:`arrays.DatetimeArray`
      * :class:`arrays.TimedeltaArray`

    When data with a ``datetime64[ns]`` or ``timedelta64[ns]`` dtype is
    passed, pandas will always return a ``DatetimeArray`` or ``TimedeltaArray``
    rather than a ``NumpyExtensionArray``. This is for symmetry with the case of
    timezone-aware data, which NumPy does not natively support.

    >>> pd.array(['2015', '2016'], dtype='datetime64[ns]')
    <DatetimeArray>
    ['2015-01-01 00:00:00', '2016-01-01 00:00:00']
    Length: 2, dtype: datetime64[ns]

    >>> pd.array(["1h", "2h"], dtype='timedelta64[ns]')
    <TimedeltaArray>
    ['0 days 01:00:00', '0 days 02:00:00']
    Length: 2, dtype: timedelta64[ns]

    Examples
    --------
    If a dtype is not specified, pandas will infer the best dtype from the values.
    See the description of `dtype` for the types pandas infers for.

    >>> pd.array([1, 2])
    <IntegerArray>
    [1, 2]
    Length: 2, dtype: Int64

    >>> pd.array([1, 2, np.nan])
    <IntegerArray>
    [1, 2, <NA>]
    Length: 3, dtype: Int64

    >>> pd.array([1.1, 2.2])
    <FloatingArray>
    [1.1, 2.2]
    Length: 2, dtype: Float64

    >>> pd.array(["a", None, "c"])
    <StringArray>
    ['a', <NA>, 'c']
    Length: 3, dtype: string

    >>> with pd.option_context("string_storage", "pyarrow"):
    ...     arr = pd.array(["a", None, "c"])
    ...
    >>> arr
    <ArrowStringArray>
    ['a', <NA>, 'c']
    Length: 3, dtype: string

    >>> pd.array([pd.Period('2000', freq="D"), pd.Period("2000", freq="D")])
    <PeriodArray>
    ['2000-01-01', '2000-01-01']
    Length: 2, dtype: period[D]

    You can use the string alias for `dtype`

    >>> pd.array(['a', 'b', 'a'], dtype='category')
    ['a', 'b', 'a']
    Categories (2, object): ['a', 'b']

    Or specify the actual dtype

    >>> pd.array(['a', 'b', 'a'],
    ...          dtype=pd.CategoricalDtype(['a', 'b', 'c'], ordered=True))
    ['a', 'b', 'a']
    Categories (3, object): ['a' < 'b' < 'c']

    If pandas does not infer a dedicated extension type a
    :class:`arrays.NumpyExtensionArray` is returned.

    >>> pd.array([1 + 1j, 3 + 2j])
    <NumpyExtensionArray>
    [(1+1j), (3+2j)]
    Length: 2, dtype: complex128

    As mentioned in the "Notes" section, new extension types may be added
    in the future (by pandas or 3rd party libraries), causing the return
    value to no longer be a :class:`arrays.NumpyExtensionArray`. Specify the
    `dtype` as a NumPy dtype if you need to ensure there's no future change in
    behavior.

    >>> pd.array([1, 2], dtype=np.dtype("int32"))
    <NumpyExtensionArray>
    [1, 2]
    Length: 2, dtype: int32

    `data` must be 1-dimensional. A ValueError is raised when the input
    has the wrong dimensionality.

    >>> pd.array(1)
    Traceback (most recent call last):
      ...
    ValueError: Cannot pass scalar '1' to 'pandas.array'.
    r   )	BooleanArrayDatetimeArrayr)   FloatingArrayIntegerArrayIntervalArrayNumpyExtensionArrayPeriodArrayTimedeltaArrayStringDtypezCannot pass scalar 'z' to 'pandas.array'.z'Cannot pass DataFrame to 'pandas.array'NT)extract_numpyr,   r.   )skipnaperiodr.   intervaldatetime	timedeltastringintegeremptyr,   )floatingzmixed-integer-floatbooleanMmmMzdatetime64 and timedelta64 dtype resolutions other than 's', 'ms', 'us', and 'ns' are deprecated. In future releases passing unsupported resolutions will raise an exception.)
stacklevel).pandas.core.arraysr1   r2   r)   r3   r4   r5   r6   r7   r8   pandas.core.arrays.string_r:   r   	is_scalar
ValueError
isinstancer"   	TypeErrorr%   r$   r,   extract_arrayr    r.   r   construct_array_type_from_sequenceinfer_dtyper   r   r   r   r   r   
startswithhasattrlengetattrnpfloat16is_np_dtyper   warningswarnFutureWarningr   )r*   r,   r.   r1   r2   r)   r3   r4   r5   r6   r7   r8   r:   msgclsinferred_dtypeperiod_data rd   }/var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/pandas/core/construction.pyarrayJ   sv    ,S







	rf   >	   indexseries
multiindex
rangeindexperiodindexdatetimeindexintervalindextimedeltaindexcategoricalindex.objSeries | Indexr;   extract_ranger   c                 C     d S Nrd   rp   r;   rr   rd   rd   re   rR        rR   r   T | ArrayLikec                 C  rs   rt   rd   ru   rd   rd   re   rR     rv   Fc                 C  sH   t | dd}|tv r|dkr|r| jS | S | jS |r"|dkr"|  S | S )a  
    Extract the ndarray or ExtensionArray from a Series or Index.

    For all other types, `obj` is just returned as is.

    Parameters
    ----------
    obj : object
        For Series / Index, the underlying ExtensionArray is unboxed.

    extract_numpy : bool, default False
        Whether to extract the ndarray from a NumpyExtensionArray.

    extract_range : bool, default False
        If we have a RangeIndex, return range._values if True
        (which is a materialized integer ndarray), otherwise return unchanged.

    Returns
    -------
    arr : object

    Examples
    --------
    >>> extract_array(pd.Series(['a', 'b', 'c'], dtype='category'))
    ['a', 'b', 'c']
    Categories (3, object): ['a', 'b', 'c']

    Other objects like lists, arrays, and DataFrames are just passed through.

    >>> extract_array([1, 2, 3])
    [1, 2, 3]

    For an ndarray-backed Series / Index the ndarray is returned.

    >>> extract_array(pd.Series([1, 2, 3]))
    array([1, 2, 3])

    To extract all the way down to the ndarray, pass ``extract_numpy=True``.

    >>> extract_array(pd.Series([1, 2, 3]), extract_numpy=True)
    array([1, 2, 3])
    _typNrj   npy_extension)rY   _typs_valuesto_numpy)rp   r;   rr   typrd   rd   re   rR     s   -c                 C  sp   t | tjr6| jjdkrddlm} t| j}|j| |dS | jjdkr6ddlm	} t| j}|j| |dS | S )zS
    Wrap datetime64 and timedelta64 ndarrays in DatetimeArray/TimedeltaArray.
    rH   r   )r2   r,   rI   )r8   )
rP   rZ   ndarrayr,   kindrL   r2   r   rT   r8   )arrr2   r,   r8   rd   rd   re   ensure_wrapped_if_datetimelike  s   

r   ma.MaskedArray
np.ndarrayc                 C  sd   t | }| r,t| jtj\}}ttj|}t | j	|dd} | 
  || |< | S |  } | S )z?
    Convert numpy MaskedArray to ensure mask is softened.
    Tr?   )r	   getmaskarrayanyr   r,   rZ   nanr   asarrayastypesoften_maskr.   )r*   maskr,   
fill_valuerd   rd   re   sanitize_masked_array  s   
r   allow_2drg   Index | NoneDtypeObj | Noner   c          
      C  s
  |}t | tjrt| } t |tr|j}d}t | tr&| jtkr&|du r&d}t	| ddd} t | t
jrE| jdkrE|du r?| j}t| } nt | trPt| } d}t| s||du r\tdt | trrt rr|du rrddlm} |d}t| t||} | S t | tr|dur| j||d	}n|r|  }n| }nt |trt|  | }	|	j| ||d
}nt | t
jr
t | t
j r| j!} |du r| }| jtkrt"| }|rt rt#|r| }n| jj$dkrt rddlm} |dd}| j| |d}|| u r|r| }nct%| ||}n\t&| dr)|st
'| } nt
j(| |d	} t)| ||d|dS t|  t*| } t| dkrF|du rFt
j(g t
j+d}n |durRt%| ||}nt,| }|jtkrft-t
j|}t"|}t.|| |||d}t |t
jrt-t
j|}t/|| ||}|S )a  
    Sanitize input data to an ndarray or ExtensionArray, copy if specified,
    coerce to the dtype if specified.

    Parameters
    ----------
    data : Any
    index : Index or None, default None
    dtype : np.dtype, ExtensionDtype, or None, default None
    copy : bool, default False
    allow_2d : bool, default False
        If False, raise if we have a 2D Arraylike.

    Returns
    -------
    np.ndarray or ExtensionArray
    FNT)r;   rr   r   z2index must be specified when data is not list-liker9   pyarrow_numpyr?   r<   U)storager~   	__array__)rg   r,   r.   r   r   )0rP   r	   MaskedArrayr   r!   numpy_dtyper$   r,   objectrR   rZ   r   ndimr   item_from_zerodimrangerange_to_ndarrayr   rO   strr
   rM   r:   r   rX   r#   r   r.   r   _sanitize_non_orderedrS   rT   matrixAr   r   r   	_try_castrW   r   rf   sanitize_arraylistfloat64r   r   _sanitize_ndim_sanitize_str_dtypes)
r*   rg   r,   r.   r   original_dtypeobject_indexr:   subarrra   rd   rd   re   r     s   







	
r   rngr   c                 C  s   zt j| j| j| jdd}W |S  tyY   | jdkr | jdks.| jd  k r,| jkrPn n"zt j| j| j| jdd}W Y |S  tyO   tt| }Y Y |S w tt| }Y |S w )z)
    Cast a range object to ndarray.
    int64r~   r   uint64)rZ   arangestartstopstepOverflowErrorr   r   )r   r   rd   rd   re   r     s   
0r   Nonec                 C  s(   t | ttfrtdt| j ddS )z@
    Raise only for unordered sets, e.g., not for dict_keys
    'z' type is unorderedN)rP   set	frozensetrQ   type__name__)r*   rd   rd   re   r     s   r   resultc                C  s   t | dddkrtd| jdkrt| |} | S | jdkrWt|tjr0|r'| S td|j dt|rPt|t	rPt
j|tdd} | }|j| |d} | S t
j||d} | S )	z6
    Ensure we have a 1-dimensional result array.
    r   r   z(result should be arraylike with ndim > 0   z1Data must be 1-dimensional, got ndarray of shape z insteadr   r~   )rY   rO   r   _maybe_repeatrP   rZ   r   shaper   r   comasarray_tuplesafer,   rS   rT   )r   r*   r,   rg   r   ra   rd   rd   re   r     s&   


r   np.dtype | Nonec                 C  s^   t | jjtr-t|s-tt|stj	||d}|s%tj	|t
d} | S tj|t
|d} | S )z=
    Ensure we have a dtype that is supported by pandas.
    r~   r<   )
issubclassr,   r   r   r   rN   rZ   allr&   r   r   rf   )r   r*   r,   r.   rd   rd   re   r     s   	
r   r   c                 C  s<   |durdt |   krt |krn | S | t |} | S )zx
    If we have a length-1 array and an index describing how long we expect
    the result to be, repeat the array.
    Nr   )rX   repeat)r   rg   rd   rd   re   r     s
   r   list | np.ndarraynp.dtypec                 C  s   t | tj}|tkr|st| }|S t| j||dS |jdkrE|r5ttj| } | j	}| j
dkr4|  } nt| f}tj| d|d|S |jdv rOt| |S |jdv r[t| |}|S |sftj| |d}|S tj| ||d	}|S )
aL  
    Convert input to numpy ndarray and optionally cast to a given dtype.

    Parameters
    ----------
    arr : ndarray or list
        Excludes: ExtensionArray, Series, Index.
    dtype : np.dtype
    copy : bool
        If False, don't copy the data if not needed.

    Returns
    -------
    np.ndarray or ExtensionArray
    r?   r   r   F)convert_na_valuer.   rJ   iur~   r<   )rP   rZ   r   r   r   r   r   r   r   r   r   ravelrX   r   ensure_string_arrayreshaper   r   r   rf   )r   r,   r.   
is_ndarrayr   r   rd   rd   re   r     s6   






r   )NT)r*   r+   r,   r-   r.   r/   r0   r)   )..)rp   rq   r;   r/   rr   r/   r0   r   )rp   r   r;   r/   rr   r/   r0   rw   )FF)r*   r   r0   r   )NF)
rg   r   r,   r   r.   r/   r   r/   r0   r   )r   r   r0   r   )r0   r   )
r   r   r,   r   rg   r   r   r/   r0   r   )r   r   r,   r   r.   r/   r0   r   )r   r   rg   r   r0   r   )r   r   r,   r   r.   r/   r0   r   )M__doc__
__future__r   collections.abcr   typingr   r   r   r   r   r]   numpyrZ   r	   pandas._configr
   pandas._libsr   pandas._libs.tslibsr   r   r   pandas._typingr   r   r   r   r   pandas.util._exceptionsr   pandas.core.dtypes.baser   pandas.core.dtypes.castr   r   r   r   r   r   r   pandas.core.dtypes.commonr   r   r   r    pandas.core.dtypes.dtypesr!   pandas.core.dtypes.genericr"   r#   r$   r%   pandas.core.dtypes.missingr&   pandas.core.commoncorecommonr   pandasr'   r(   pandas.core.arrays.baser)   rf   r   rz   rR   r   r   r   r   r   r   r   r   r   rd   rd   rd   re   <module>   sj    $	  ;A
 


'
