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__/datetimes.cpython-36.pyc
3

���h;2�@s>ddlmZmZmZmZddlmZmZddlZddlZ	ddl
mZmZddl
mZmZmZmZmZmZmZmZmZmZmZmZmZddlmZddlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.ddl/m0Z0dd	l1m2Z2m3Z3m4Z4dd
l5m6Z6ddl7m8Z8ddl9m:Z;dd
l<m=Z=ddl>j?j@ZAddlBmCZCddlDmEZEmFZFmGZGedd�ZHdd�ZId0dd�ZJGdd�de;jKe;jLe;jM�ZNd1dd�ZOd2dd�ZPdd�ZQeeeeeed�dd �ZRd!d"�ZSeeeed#�d$d%�ZTeeeeeed&�d'd(�ZUeeeeeVd)�d*d+�ZWd,d-�ZXdddeE�fd.d/�ZYdS)3�)�datetime�time�	timedelta�tzinfo)�Optional�UnionN)�lib�tslib)
�NaT�
Resolution�	Timestamp�
conversion�fields�get_resolution�iNaT�ints_to_pydatetime�is_date_array_normalized�normalize_i8_timestamps�	timezones�	to_offset�tzconversion)�PerformanceWarning)�DT64NS_DTYPE�INT64_DTYPE�
is_bool_dtype�is_categorical_dtype�is_datetime64_any_dtype�is_datetime64_dtype�is_datetime64_ns_dtype�is_datetime64tz_dtype�is_dtype_equal�is_extension_array_dtype�is_float_dtype�is_object_dtype�is_period_dtype�	is_sparse�is_string_dtype�is_timedelta64_dtype�pandas_dtype)�DatetimeTZDtype)�
ABCIndexClass�ABCPandasArray�	ABCSeries)�isna)�checked_add_with_arr)�datetimelike)�generate_regular_range)�get_period_alias)�BDay�Day�TickcCs|dkrtSt|d�SdS)z�
    Return a datetime64[ns] dtype appropriate for the given timezone.

    Parameters
    ----------
    tz : tzinfo or None

    Returns
    -------
    np.dtype or Datetime64TZDType
    N)�tz)rr))r5�r6�>/tmp/pip-build-5_djhm0z/pandas/pandas/core/arrays/datetimes.py�tz_to_dtype;sr8cs �fdd�}||_||_t|�S)Ncs�|j}|jdk	r&tj|j�r&|j�}�|jkr��jd	�rv|j}d}|rb|j}|j	d|j	dd��}t
j|�|j|�}nt
j
|��}|S�|jkr�t
j|��}|j|dd�}nt
j
|��}|j|ddd�}|S)
N�start�end�Z
startingMonth�month)�
fill_value�float64)r=�convert)r9r:)�asi8r5r�is_utc�_local_timestamps�	_bool_ops�endswith�freq�kwds�getrZget_start_end_field�freqstrZget_date_field�_object_ops�get_date_name_field�_maybe_mask_results)�self�valuesrEZmonth_kwrF�result)�fieldr6r7�fNs*


z_field_accessor.<locals>.f)�__name__�__doc__�property)�namerOZ	docstringrPr6)rOr7�_field_accessorMs"rUcs�eZdZUdZdZeZeej	fZ
eZddddddd	gZ
d
dgZdd
ddddddddddddddgZdddgZeee
eZdd d!d"d#d$d%d&d'd(g
Zd)Zeejefd*Zed*d+fd,d-�Zed*efd.d/��Zed*d+d*ejd+d+d0fd1d2��Zed�d3d4��Z d5d6�Z!d7d8�Z"d�e#d9�d:d;�Z$d<d=�Z%e&d>d?��Z'e&eejefd@�dAdB��Ze&dCdD��Z(e(j)dEdD��Z(e&dFdG��Z*e&dHdI��Z+e&e,d@�dJdK��Z-d�ej.d@��fdLdM�
Z/dNdO�Z0d�dQdR�Z1d�dTdU�Z2e#d@�dVdW�Z3dXdY�Z4dZd[�Z5d\d]�Z6d^d_�Z7d`da�Z8dbdc�Z9d�ddde�Z:ej.d@�dfdg�Z;dhdi�Z<d�djdk�Z=dldm�Z>d�dndo�Z?d�dpdq�Z@e&drds��ZAe&dtdu��ZBe&dvdw��ZCdxdy�ZDe&dzd{��ZEeEZFeGdd|d}�ZHeGd
d~d�ZIeGdd�d��ZJeGdd�d��ZKeGdd�d��ZLeGdd�d��ZMeGdd�d��ZNeGdd�d��ZOd�ZPeGdd�eP�ZQeQZReGdd�d��ZSeGdd�d��ZTeGdd�d��ZUeUZVd�ZWeGddeWjXd�d���ZYeGddeWjXd�d���ZZeGddd��Z[eGddd��Z\eGddd��Z]eGddd��Z^eGd	d	d��Z_d�d��Z`�ZaS)��
DatetimeArraya�
    Pandas ExtensionArray for tz-naive or tz-aware datetime data.

    .. versionadded:: 0.24.0

    .. warning::

       DatetimeArray is currently experimental, and its API may change
       without warning. In particular, :attr:`DatetimeArray.dtype` is
       expected to change to always be an instance of an ``ExtensionDtype``
       subclass.

    Parameters
    ----------
    values : Series, Index, DatetimeArray, ndarray
        The datetime data.

        For DatetimeArray `values` (or a Series or Index boxing one),
        `dtype` and `freq` will be extracted from `values`.

    dtype : numpy.dtype or DatetimeTZDtype
        Note that the only NumPy dtype allowed is 'datetime64[ns]'.
    freq : str or Offset, optional
        The frequency.
    copy : bool, default False
        Whether to copy the underlying array of values.

    Attributes
    ----------
    None

    Methods
    -------
    None
    Z
datetimearray�is_month_start�is_month_end�is_quarter_start�is_quarter_end�
is_year_start�is_year_end�is_leap_yearrEr5�yearr<�day�hour�minute�second�
weekofyear�week�weekday�	dayofweek�	dayofyear�quarter�
days_in_month�daysinmonth�microsecond�
nanosecond�dater�timetz�	to_period�tz_localize�
tz_convert�	normalize�strftime�round�floor�ceil�
month_name�day_namei�NFcCs�t|ttf�r|j}t|dd�}t|t|��r�t|dd�}|rV|jdkrVt|jd�}nB|r�|jr�tj	||j�s�d|�d|j�d�}t
|��n|jr�|j}|dkr�|j}|j
}t|tj�s�tdt|�j�d���|jdkr�td��|jdkr�|jt�}|jtk�rtd
|j�d���t|�}|dk�r,td��|�r:|j�}|�rHt|�}t|dd��rhttj|j�d�}||_
||_||_|dk�r�|dk	�r�t|�j||�dS)N�_freqr5)r5z1Timezone of the array and 'dtype' do not match. 'z' != '�'zUnexpected type 'zX'. 'values' must be a DatetimeArray ndarray, or Series or Index containing one of those.��z.Only 1-dimensional input arrays are supported.�i8zBThe dtype of 'values' is incorrect. Must be 'datetime64[ns]'. Got z	 instead.�inferzTFrequency inference not allowed in DatetimeArray.__init__. Use 'pd.array()' instead.)r{r|)�
isinstancer,r*�_values�getattr�typer5r)r�
tz_compare�	TypeError�dtyperE�_data�np�ndarray�
ValueErrorrQ�ndim�viewr�_validate_dt64_dtype�copyrZtz_standardize�_dtypery�_validate_frequency)rLrMr�rEr��
inferred_freq�dtz�msgr6r6r7�__init__�sR





zDatetimeArray.__init__cCsRt|tj�st�|jtkr2|jdks(t�|jt�}tj|�}||_	||_
||_|S)Nr})rr�r��AssertionErrorr�rr��object�__new__r�ryr�)�clsrMrEr�rNr6r6r7�_simple_news


zDatetimeArray._simple_new�raisec		Cs�|dk}	|tjk	r|nd}tj|�\}}
t|||||||d�\}}}tj|||
�\}}
|	r^d}t|�}|j|||d�}
|dkr�|dk	r�|j|
||d�n|
r�t	|
j
�|
_|
S)N)r�r�r5�dayfirst�	yearfirst�	ambiguous)rEr�)r�)r�
no_default�dtlZmaybe_infer_freq�sequence_to_dt64nsZvalidate_inferred_freqr8r�r�rr�ry)r��datar�r�r5rEr�r�r�Z
explicit_noneZ
freq_inferZsubarrr�rNr6r6r7�_from_sequence,s*zDatetimeArray._from_sequencec
Cs�tj|�}|dkr2tdd�|||gD��r2td��tj||||�dkrNtd��t|�}|dk	rft|�}|dk	rvt|�}|tks�|tkr�td��tj	|	�\}
}t
|||�\}}}t|||�}|dk	�r|dkr�dn|j}
|dkr�dn|j}t
||
|||||�}t
|||||||�}|dk	�rt|t��rN|dk	�r:|jd�}|dk	�rN|jd�}t|t��rjt||||�}n*t||||d�}tjdd	�|D�tjd
�}|dk	�r�|jn|j}|j||t|�d�}|dk	�r`|jdk�r`tj|j|||d�}||�}|dk	�r|j|�j}|dk	�r`|j|�j}nBtjd
|j|j|dd
�|j}t|�}|j|jddd�d|d�}|
�r�t |��r�|d
|k�r�|dd�}|�r�t |��r�|d|k�r�|dd�}t|�}|j|j||d�S)Ncss|]}|dkVqdS)Nr6)�.0�xr6r6r7�	<genexpr>hsz0DatetimeArray._generate_range.<locals>.<genexpr>z1Must provide freq argument if no data is supplied�zVOf the four parameters: start, end, periods, and freq, exactly three must be specifiedz$Neither `start` nor `end` can be NaT)r9r:�periods�offsetcSsg|]
}|j�qSr6)�value)r�r�r6r6r7�
<listcomp>�sz1DatetimeArray._generate_range.<locals>.<listcomp>)r�)rEr�)r��nonexistentr�int64zM8[ns]F)r�r{���r�)!r�Zvalidate_periods�anyr��comZcount_not_nonerrr
Zvalidate_endpoints�_maybe_normalize_endpoints�_infer_tz_from_endpointsr5�_maybe_localize_pointrr3rpr4r0�generate_ranger��arrayr�r�r8r�tz_localize_to_utcr@Zasm8Zlinspacer��astype�len)r�r9r:r�rEr5rrr�r��closedZleft_closedZright_closed�_normalizedZstart_tzZend_tzrMZxdrZ_tz�indexZarrr�r6r6r7�_generate_rangeYsl
 







  zDatetimeArray._generate_rangecCs6t||j�r|tk	rtd��t|�s0|j|�|jS)Nz'value' should be a Timestamp.)r�_scalar_typer
r�r-�_check_compatible_withr�)rLr�r6r6r7�
_unbox_scalar�s

zDatetimeArray._unbox_scalarcCst||jd�S)N)r5)rr5)rLr�r6r6r7�_scalar_from_string�sz!DatetimeArray._scalar_from_string)�setitemcCsH|tkrdS|j|�|rDtj|j|j�sDtd|j�d|j�d���dS)NzTimezones don't match. 'z != rz)r
�_assert_tzawareness_compatrr�r5r�)rL�otherr�r6r6r7r��s
z$DatetimeArray._check_compatible_withcCs
d|_dS)N)ry)rLr6r6r7�_maybe_clear_freq�szDatetimeArray._maybe_clear_freqcs�fdd�S)Ncst|�j�jd�S)N)rEr5)rrEr5)r�)rLr6r7�<lambda>�sz)DatetimeArray._box_func.<locals>.<lambda>r6)rLr6)rLr7�	_box_func�szDatetimeArray._box_func)�returncCs|jS)a%
        The dtype for the DatetimeArray.

        .. warning::

           A future version of pandas will change dtype to never be a
           ``numpy.dtype``. Instead, :attr:`DatetimeArray.dtype` will
           always be an instance of an ``ExtensionDtype`` subclass.

        Returns
        -------
        numpy.dtype or DatetimeTZDtype
            If the values are tz-naive, then ``np.dtype('datetime64[ns]')``
            is returned.

            If the values are tz-aware, then the ``DatetimeTZDtype``
            is returned.
        )r�)rLr6r6r7r��szDatetimeArray.dtypecCst|jdd�S)z�
        Return timezone, if any.

        Returns
        -------
        datetime.tzinfo, pytz.tzinfo.BaseTZInfo, dateutil.tz.tz.tzfile, or None
            Returns None when the array is tz-naive.
        r5N)r�r�)rLr6r6r7r5�szDatetimeArray.tzcCstd��dS)NzNCannot directly set timezone. Use tz_localize() or tz_convert() as appropriate)�AttributeError)rLr�r6r6r7r5scCs|jS)z(
        Alias for tz attribute
        )r5)rLr6r6r7r
szDatetimeArray.tzinfocCst|j|j�S)zN
        Returns True if all of the dates are at midnight ("no time")
        )rr@r5)rLr6r6r7�
is_normalizedszDatetimeArray.is_normalizedcCst|j|j�S)N)rr@r5)rLr6r6r7�_resolution_objszDatetimeArray._resolution_objcs |dkr|jrt}t�j|d�S)N)r�)r5r��super�	__array__)rLr�)�	__class__r6r7r�szDatetimeArray.__array__c
cs�|j}t|�}d}t||�d}xZt|�D]N}||}t|d||�}t|||�|j|jdd�}x|D]
}	|	VqlWq,WdS)zt
        Return an iterator over the boxed values

        Yields
        ------
        tstamp : Timestamp
        i'r{�	timestamp)r5rE�boxN)r@r��int�range�minrr5rE)
rLr��length�	chunksize�chunks�iZstart_iZend_iZ	converted�vr6r6r7�__iter__&s

zDatetimeArray.__iter__TcCs�t|�}t|�rnt||j�rnt|dd�}t|jdd�dkrF|j|�S|j|�}|r\|j�}|dkrj|j}|St	|j�r�t|j|�r�|r�|j�S|St
|�r�|j|jd�St
jj|||�S)Nr5)rE)r(rr r�r�rprqr�r�rr$rorEr��DatetimeLikeArrayMixinr�)rLr�r�Znew_tzrNr6r6r7r�=s$

zDatetimeArray.astyper
cKs8ddlm}|||�}tj|jj�|j||d�j|j�S)Nr)�"_get_format_datetime64_from_values)r5�format�na_rep)	Zpandas.io.formats.formatr�r	Zformat_array_from_datetimer@�ravelr5�reshape�shape)rLr�Zdate_format�kwargsr��fmtr6r6r7�_format_native_types]s

z"DatetimeArray._format_native_typescCs6t|tj�rt|�}t|d�s"dS|j}tj|j|�S)NrF)rr��
datetime64r�hasattrrrr�)rLr��other_tzr6r6r7�_has_same_tzis
zDatetimeArray._has_same_tzcCsbt|dd�}t|dd�}t|�r(|jj}|tkr2n,|jdkrN|dk	r^td��n|dkr^td��dS)Nrr�z;Cannot compare tz-naive and tz-aware datetime-like objects.z:Cannot compare tz-naive and tz-aware datetime-like objects)r�rr�r5r
r�)rLr�r�Zother_dtyper6r6r7r�us
z(DatetimeArray._assert_tzawareness_compatcCs�t|�t|�krtd��t|tj�r<t|�s0t�t|�|�}|j|�sZt	t|�j
�d���|j}|j}|j|jB}t
|||d�}|js�|jr�t||<|jd�S)z3subtract DatetimeArray/Index or ndarray[datetime64]z$cannot add indices of unequal lengthz9 subtraction must have the same timezones or no timezones)�arr_maskztimedelta64[ns])r�r�rr�r�rr�r�r�r�rQr@�_isnanr.�_hasnansrr�)rLr�Zself_i8Zother_i8r��
new_valuesr6r6r7�_sub_datetime_arraylike�s
z%DatetimeArray._sub_datetime_arraylikecCs�|jdkr |j�j|�j|j�St|t�s0t�y>|jdk	rH|j	d�}n|}|j
|�}tj|�}|j	|j�}WnLt
k
r�tjdt�|jd�|}t|�s�t|�j|�j	|j�SYnXt|�j|�S)Nr|zBNon-vectorized DateOffset being applied to Series or DatetimeIndex�O)r�r��_add_offsetr�r�rr4r�r5rpZ_apply_arrayrVr��NotImplementedError�warnings�warnrr�r�r�r�)rLr�rMrNr6r6r7r��s$



zDatetimeArray._add_offsetcCsxt|ttjf�st�|tk	s t�t|�}|tkr8|tS|j|�sJtd��|j	}t
||j|jd�}|j
|�}|jd�S)NzBTimestamp subtraction must have the same timezones or no timezones)r�ztimedelta64[ns])rrr�r�r�r
rr�r�r@r.r�r�rKr�)rLr�r}rNr6r6r7�_sub_datetimelike_scalar�s

z&DatetimeArray._sub_datetimelike_scalarcCstj|j|j�S)z�
        Convert to an i8 (unix-like nanosecond timestamp) representation
        while keeping the local timezone and not using UTC.
        This is used to calculate time-of-day information as if the timestamps
        were timezone-naive.
        )r�tz_convert_from_utcr@r5)rLr6r6r7rB�szDatetimeArray._local_timestampscCs8tj|�}|jdkrtd��t|�}|j|j||jd�S)a	
        Convert tz-aware Datetime Array/Index from one time zone to another.

        Parameters
        ----------
        tz : str, pytz.timezone, dateutil.tz.tzfile or None
            Time zone for time. Corresponding timestamps would be converted
            to this time zone of the Datetime Array/Index. A `tz` of None will
            convert to UTC and remove the timezone information.

        Returns
        -------
        Array or Index

        Raises
        ------
        TypeError
            If Datetime Array/Index is tz-naive.

        See Also
        --------
        DatetimeIndex.tz : A timezone that has a variable offset from UTC.
        DatetimeIndex.tz_localize : Localize tz-naive DatetimeIndex to a
            given time zone, or remove timezone from a tz-aware DatetimeIndex.

        Examples
        --------
        With the `tz` parameter, we can change the DatetimeIndex
        to other time zones:

        >>> dti = pd.date_range(start='2014-08-01 09:00',
        ...                     freq='H', periods=3, tz='Europe/Berlin')

        >>> dti
        DatetimeIndex(['2014-08-01 09:00:00+02:00',
                       '2014-08-01 10:00:00+02:00',
                       '2014-08-01 11:00:00+02:00'],
                      dtype='datetime64[ns, Europe/Berlin]', freq='H')

        >>> dti.tz_convert('US/Central')
        DatetimeIndex(['2014-08-01 02:00:00-05:00',
                       '2014-08-01 03:00:00-05:00',
                       '2014-08-01 04:00:00-05:00'],
                      dtype='datetime64[ns, US/Central]', freq='H')

        With the ``tz=None``, we can remove the timezone (after converting
        to UTC if necessary):

        >>> dti = pd.date_range(start='2014-08-01 09:00', freq='H',
        ...                     periods=3, tz='Europe/Berlin')

        >>> dti
        DatetimeIndex(['2014-08-01 09:00:00+02:00',
                       '2014-08-01 10:00:00+02:00',
                       '2014-08-01 11:00:00+02:00'],
                        dtype='datetime64[ns, Europe/Berlin]', freq='H')

        >>> dti.tz_convert(None)
        DatetimeIndex(['2014-08-01 07:00:00',
                       '2014-08-01 08:00:00',
                       '2014-08-01 09:00:00'],
                        dtype='datetime64[ns]', freq='H')
        Nz?Cannot convert tz-naive timestamps, use tz_localize to localize)r�rE)r�maybe_get_tzr5r�r8r�r@rE)rLr5r�r6r6r7rq�s@

zDatetimeArray.tz_convertcCs�d}||kr t|t�r td��|jdk	rN|dkrDtj|j|j�}qltd��ntj	|�}tj
|j|||d�}|jt�}t
|�}d}tj|�s�t|�d	kr�t|d
�r�|j}n|dkr�|jdkr�|j}|j|||d�S)
a�
        Localize tz-naive Datetime Array/Index to tz-aware
        Datetime Array/Index.

        This method takes a time zone (tz) naive Datetime Array/Index object
        and makes this time zone aware. It does not move the time to another
        time zone.
        Time zone localization helps to switch from time zone aware to time
        zone unaware objects.

        Parameters
        ----------
        tz : str, pytz.timezone, dateutil.tz.tzfile or None
            Time zone to convert timestamps to. Passing ``None`` will
            remove the time zone information preserving local time.
        ambiguous : 'infer', 'NaT', bool array, default 'raise'
            When clocks moved backward due to DST, ambiguous times may arise.
            For example in Central European Time (UTC+01), when going from
            03:00 DST to 02:00 non-DST, 02:30:00 local time occurs both at
            00:30:00 UTC and at 01:30:00 UTC. In such a situation, the
            `ambiguous` parameter dictates how ambiguous times should be
            handled.

            - 'infer' will attempt to infer fall dst-transition hours based on
              order
            - bool-ndarray where True signifies a DST time, False signifies a
              non-DST time (note that this flag is only applicable for
              ambiguous times)
            - 'NaT' will return NaT where there are ambiguous times
            - 'raise' will raise an AmbiguousTimeError if there are ambiguous
              times.

        nonexistent : 'shift_forward', 'shift_backward, 'NaT', timedelta, default 'raise'
            A nonexistent time does not exist in a particular timezone
            where clocks moved forward due to DST.

            - 'shift_forward' will shift the nonexistent time forward to the
              closest existing time
            - 'shift_backward' will shift the nonexistent time backward to the
              closest existing time
            - 'NaT' will return NaT where there are nonexistent times
            - timedelta objects will shift nonexistent times by the timedelta
            - 'raise' will raise an NonExistentTimeError if there are
              nonexistent times.

            .. versionadded:: 0.24.0

        Returns
        -------
        Same type as self
            Array/Index converted to the specified time zone.

        Raises
        ------
        TypeError
            If the Datetime Array/Index is tz-aware and tz is not None.

        See Also
        --------
        DatetimeIndex.tz_convert : Convert tz-aware DatetimeIndex from
            one time zone to another.

        Examples
        --------
        >>> tz_naive = pd.date_range('2018-03-01 09:00', periods=3)
        >>> tz_naive
        DatetimeIndex(['2018-03-01 09:00:00', '2018-03-02 09:00:00',
                       '2018-03-03 09:00:00'],
                      dtype='datetime64[ns]', freq='D')

        Localize DatetimeIndex in US/Eastern time zone:

        >>> tz_aware = tz_naive.tz_localize(tz='US/Eastern')
        >>> tz_aware
        DatetimeIndex(['2018-03-01 09:00:00-05:00',
                       '2018-03-02 09:00:00-05:00',
                       '2018-03-03 09:00:00-05:00'],
                      dtype='datetime64[ns, US/Eastern]', freq=None)

        With the ``tz=None``, we can remove the time zone information
        while keeping the local time (not converted to UTC):

        >>> tz_aware.tz_localize(None)
        DatetimeIndex(['2018-03-01 09:00:00', '2018-03-02 09:00:00',
                       '2018-03-03 09:00:00'],
                      dtype='datetime64[ns]', freq=None)

        Be careful with DST changes. When there is sequential data, pandas can
        infer the DST time:

        >>> s = pd.to_datetime(pd.Series(['2018-10-28 01:30:00',
        ...                               '2018-10-28 02:00:00',
        ...                               '2018-10-28 02:30:00',
        ...                               '2018-10-28 02:00:00',
        ...                               '2018-10-28 02:30:00',
        ...                               '2018-10-28 03:00:00',
        ...                               '2018-10-28 03:30:00']))
        >>> s.dt.tz_localize('CET', ambiguous='infer')
        0   2018-10-28 01:30:00+02:00
        1   2018-10-28 02:00:00+02:00
        2   2018-10-28 02:30:00+02:00
        3   2018-10-28 02:00:00+01:00
        4   2018-10-28 02:30:00+01:00
        5   2018-10-28 03:00:00+01:00
        6   2018-10-28 03:30:00+01:00
        dtype: datetime64[ns, CET]

        In some cases, inferring the DST is impossible. In such cases, you can
        pass an ndarray to the ambiguous parameter to set the DST explicitly

        >>> s = pd.to_datetime(pd.Series(['2018-10-28 01:20:00',
        ...                               '2018-10-28 02:36:00',
        ...                               '2018-10-28 03:46:00']))
        >>> s.dt.tz_localize('CET', ambiguous=np.array([True, True, False]))
        0   2018-10-28 01:20:00+02:00
        1   2018-10-28 02:36:00+02:00
        2   2018-10-28 03:46:00+01:00
        dtype: datetime64[ns, CET]

        If the DST transition causes nonexistent times, you can shift these
        dates forward or backwards with a timedelta object or `'shift_forward'`
        or `'shift_backwards'`.

        >>> s = pd.to_datetime(pd.Series(['2015-03-29 02:30:00',
        ...                               '2015-03-29 03:30:00']))
        >>> s.dt.tz_localize('Europe/Warsaw', nonexistent='shift_forward')
        0   2015-03-29 03:00:00+02:00
        1   2015-03-29 03:30:00+02:00
        dtype: datetime64[ns, Europe/Warsaw]

        >>> s.dt.tz_localize('Europe/Warsaw', nonexistent='shift_backward')
        0   2015-03-29 01:59:59.999999999+01:00
        1   2015-03-29 03:30:00+02:00
        dtype: datetime64[ns, Europe/Warsaw]

        >>> s.dt.tz_localize('Europe/Warsaw', nonexistent=pd.Timedelta('1H'))
        0   2015-03-29 03:30:00+02:00
        1   2015-03-29 03:30:00+02:00
        dtype: datetime64[ns, Europe/Warsaw]
        r�r
�
shift_forward�shift_backwardzoThe nonexistent argument must be one of 'raise', 'NaT', 'shift_forward', 'shift_backward' or a timedelta objectNz,Already tz-aware, use tz_convert to convert.)r�r�r{r)r�rE)r�r
r�r�)rrr�r5rr�r@r�rr�r�r�rr8rAr�r-rEr�)rLr5r�r�Znonexistent_optionsZ	new_datesr�rEr6r6r7rp*s*





$zDatetimeArray.tz_localizecCst|j|jd�S)z�
        Return Datetime Array/Index as object ndarray of datetime.datetime
        objects.

        Returns
        -------
        datetimes : ndarray
        )r5)rr@r5)rLr6r6r7�
to_pydatetime�s	zDatetimeArray.to_pydatetimecCs(t|j|j�}t|�|�jd�j|j�S)a�
        Convert times to midnight.

        The time component of the date-time is converted to midnight i.e.
        00:00:00. This is useful in cases, when the time does not matter.
        Length is unaltered. The timezones are unaffected.

        This method is available on Series with datetime values under
        the ``.dt`` accessor, and directly on Datetime Array/Index.

        Returns
        -------
        DatetimeArray, DatetimeIndex or Series
            The same type as the original data. Series will have the same
            name and index. DatetimeIndex will have the same name.

        See Also
        --------
        floor : Floor the datetimes to the specified freq.
        ceil : Ceil the datetimes to the specified freq.
        round : Round the datetimes to the specified freq.

        Examples
        --------
        >>> idx = pd.date_range(start='2014-08-01 10:00', freq='H',
        ...                     periods=3, tz='Asia/Calcutta')
        >>> idx
        DatetimeIndex(['2014-08-01 10:00:00+05:30',
                       '2014-08-01 11:00:00+05:30',
                       '2014-08-01 12:00:00+05:30'],
                        dtype='datetime64[ns, Asia/Calcutta]', freq='H')
        >>> idx.normalize()
        DatetimeIndex(['2014-08-01 00:00:00+05:30',
                       '2014-08-01 00:00:00+05:30',
                       '2014-08-01 00:00:00+05:30'],
                       dtype='datetime64[ns, Asia/Calcutta]', freq=None)
        r~)rr@r5r�Z
_with_freqrp)rLr�r6r6r7rr�s&zDatetimeArray.normalizecCsrddlm}|jdk	r"tjdt�|dkr^|jp4|j}|dkrFtd��t	|�}|dkrZ|}|}|j
|j||jd�S)a�
        Cast to PeriodArray/Index at a particular frequency.

        Converts DatetimeArray/Index to PeriodArray/Index.

        Parameters
        ----------
        freq : str or Offset, optional
            One of pandas' :ref:`offset strings <timeseries.offset_aliases>`
            or an Offset object. Will be inferred by default.

        Returns
        -------
        PeriodArray/Index

        Raises
        ------
        ValueError
            When converting a DatetimeArray/Index with non-regular values,
            so that a frequency cannot be inferred.

        See Also
        --------
        PeriodIndex: Immutable ndarray holding ordinal values.
        DatetimeIndex.to_pydatetime: Return DatetimeIndex as object.

        Examples
        --------
        >>> df = pd.DataFrame({"y": [1, 2, 3]},
        ...                   index=pd.to_datetime(["2000-03-31 00:00:00",
        ...                                         "2000-05-31 00:00:00",
        ...                                         "2000-08-31 00:00:00"]))
        >>> df.index.to_period("M")
        PeriodIndex(['2000-03', '2000-05', '2000-08'],
                    dtype='period[M]', freq='M')

        Infer the daily frequency

        >>> idx = pd.date_range("2017-01-01", periods=2)
        >>> idx.to_period()
        PeriodIndex(['2017-01-01', '2017-01-02'],
                    dtype='period[D]', freq='D')
        r)�PeriodArrayNzNConverting to PeriodArray/Index representation will drop timezone information.z8You must pass a freq argument as current index has none.)r5)�pandas.core.arraysr�r5r�r��UserWarningrHr�r�r1Z_from_datetime64r�)rLrEr��resr6r6r7ros,
zDatetimeArray.to_periodcCsDtjdtdd�ddlm}|j|j|�j�j}|jd�}||�S)a5
        Calculate TimedeltaArray of difference between index
        values and index converted to PeriodArray at specified
        freq. Used for vectorized offsets.

        Parameters
        ----------
        freq : Period frequency

        Returns
        -------
        TimedeltaArray/Index
        z�to_perioddelta is deprecated and will be removed in a future version.  Use `dtindex - dtindex.to_period(freq).to_timestamp()` insteadr�)�
stacklevelr)�TimedeltaArrayzm8[ns])	r�r��
FutureWarningZpandas.core.arrays.timedeltasr�r@roZto_timestampr�)rLrEr�Zi8deltaZm8deltar6r6r7�to_perioddeltaYs
zDatetimeArray.to_perioddeltacCsJ|jdk	r"tj|j�r"|j�}n|j}tj|d|d�}|j|dd�}|S)a�
        Return the month names of the DateTimeIndex with specified locale.

        .. versionadded:: 0.23.0

        Parameters
        ----------
        locale : str, optional
            Locale determining the language in which to return the month name.
            Default is English locale.

        Returns
        -------
        Index
            Index of month names.

        Examples
        --------
        >>> idx = pd.date_range(start='2018-01', freq='M', periods=3)
        >>> idx
        DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'],
                      dtype='datetime64[ns]', freq='M')
        >>> idx.month_name()
        Index(['January', 'February', 'March'], dtype='object')
        Nrw)�locale)r=)r5rrArBr@rrJrK)rLr�rMrNr6r6r7rwxs
zDatetimeArray.month_namecCsJ|jdk	r"tj|j�r"|j�}n|j}tj|d|d�}|j|dd�}|S)a�
        Return the day names of the DateTimeIndex with specified locale.

        .. versionadded:: 0.23.0

        Parameters
        ----------
        locale : str, optional
            Locale determining the language in which to return the day name.
            Default is English locale.

        Returns
        -------
        Index
            Index of day names.

        Examples
        --------
        >>> idx = pd.date_range(start='2018-01-01', freq='D', periods=3)
        >>> idx
        DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'],
                      dtype='datetime64[ns]', freq='D')
        >>> idx.day_name()
        Index(['Monday', 'Tuesday', 'Wednesday'], dtype='object')
        Nrx)r�)r=)r5rrArBr@rrJrK)rLr�rMrNr6r6r7rx�s
zDatetimeArray.day_namecCs4|jdk	r"tj|j�r"|j�}n|j}t|dd�S)zX
        Returns numpy array of datetime.time. The time part of the Timestamps.
        Nr)r�)r5rrArBr@r)rL�
timestampsr6r6r7r�s
zDatetimeArray.timecCst|j|jdd�S)z�
        Returns numpy array of datetime.time also containing timezone
        information. The time part of the Timestamps.
        r)r�)rr@r5)rLr6r6r7rn�szDatetimeArray.timetzcCs4|jdk	r"tj|j�r"|j�}n|j}t|dd�S)z�
        Returns numpy array of python datetime.date objects (namely, the date
        part of Timestamps without timezone information).
        Nrm)r�)r5rrArBr@r)rLr�r6r6r7rm�s	
zDatetimeArray.datecCshddlm}|jdk	r.tj|j�r.|j�}n|j}tj|�}||dddgdd�}|j	rdd|j
|j<|S)	aL
        Returns a DataFrame with the year, week, and day calculated according to
        the ISO 8601 standard.

        .. versionadded:: 1.1.0

        Returns
        -------
        DataFrame
            with columns year, week and day

        See Also
        --------
        Timestamp.isocalendar
        datetime.date.isocalendar

        Examples
        --------
        >>> idx = pd.date_range(start='2019-12-29', freq='D', periods=4)
        >>> idx.isocalendar()
                    year  week  day
        2019-12-29  2019    52    7
        2019-12-30  2020     1    1
        2019-12-31  2020     1    2
        2020-01-01  2020     1    3
        >>> idx.isocalendar().week
        2019-12-29    52
        2019-12-30     1
        2019-12-31     1
        2020-01-01     1
        Freq: D, Name: week, dtype: UInt32
        r)�	DataFrameNr^rdr_ZUInt32)�columnsr�)Zpandasr�r5rrArBr@rZbuild_isocalendar_sarrayr�Zilocr�)rLr�rMZsarrayZiso_calendar_dfr6r6r7�isocalendar�s!

zDatetimeArray.isocalendarcCs<tjdtdd�|j�j}|jr0|jdtjd�S|jdd�S)z�
        The week ordinal of the year.

        .. deprecated:: 1.1.0

        weekofyear and week have been deprecated.
        Please use DatetimeIndex.isocalendar().week instead.
        z�weekofyear and week have been deprecated, please use DatetimeIndex.isocalendar().week instead, which returns a Series.  To exactly reproduce the behavior of week and weekofyear and return an Index, you may call pd.Int64Index(idx.isocalendar().week)r�)r�r>)r�Zna_valuer�)r�)	r�r�r�rrdZhasnans�to_numpyr��nan)rLZweek_seriesr6r6r7rcs

zDatetimeArray.weekofyear�Ya�
        The year of the datetime.

        Examples
        --------
        >>> datetime_series = pd.Series(
        ...     pd.date_range("2000-01-01", periods=3, freq="Y")
        ... )
        >>> datetime_series
        0   2000-12-31
        1   2001-12-31
        2   2002-12-31
        dtype: datetime64[ns]
        >>> datetime_series.dt.year
        0    2000
        1    2001
        2    2002
        dtype: int64
        �Ma�
        The month as January=1, December=12.

        Examples
        --------
        >>> datetime_series = pd.Series(
        ...     pd.date_range("2000-01-01", periods=3, freq="M")
        ... )
        >>> datetime_series
        0   2000-01-31
        1   2000-02-29
        2   2000-03-31
        dtype: datetime64[ns]
        >>> datetime_series.dt.month
        0    1
        1    2
        2    3
        dtype: int64
        �Da�
        The day of the datetime.

        Examples
        --------
        >>> datetime_series = pd.Series(
        ...     pd.date_range("2000-01-01", periods=3, freq="D")
        ... )
        >>> datetime_series
        0   2000-01-01
        1   2000-01-02
        2   2000-01-03
        dtype: datetime64[ns]
        >>> datetime_series.dt.day
        0    1
        1    2
        2    3
        dtype: int64
        �ha�
        The hours of the datetime.

        Examples
        --------
        >>> datetime_series = pd.Series(
        ...     pd.date_range("2000-01-01", periods=3, freq="h")
        ... )
        >>> datetime_series
        0   2000-01-01 00:00:00
        1   2000-01-01 01:00:00
        2   2000-01-01 02:00:00
        dtype: datetime64[ns]
        >>> datetime_series.dt.hour
        0    0
        1    1
        2    2
        dtype: int64
        �ma�
        The minutes of the datetime.

        Examples
        --------
        >>> datetime_series = pd.Series(
        ...     pd.date_range("2000-01-01", periods=3, freq="T")
        ... )
        >>> datetime_series
        0   2000-01-01 00:00:00
        1   2000-01-01 00:01:00
        2   2000-01-01 00:02:00
        dtype: datetime64[ns]
        >>> datetime_series.dt.minute
        0    0
        1    1
        2    2
        dtype: int64
        �sa�
        The seconds of the datetime.

        Examples
        --------
        >>> datetime_series = pd.Series(
        ...     pd.date_range("2000-01-01", periods=3, freq="s")
        ... )
        >>> datetime_series
        0   2000-01-01 00:00:00
        1   2000-01-01 00:00:01
        2   2000-01-01 00:00:02
        dtype: datetime64[ns]
        >>> datetime_series.dt.second
        0    0
        1    1
        2    2
        dtype: int64
        �usa�
        The microseconds of the datetime.

        Examples
        --------
        >>> datetime_series = pd.Series(
        ...     pd.date_range("2000-01-01", periods=3, freq="us")
        ... )
        >>> datetime_series
        0   2000-01-01 00:00:00.000000
        1   2000-01-01 00:00:00.000001
        2   2000-01-01 00:00:00.000002
        dtype: datetime64[ns]
        >>> datetime_series.dt.microsecond
        0       0
        1       1
        2       2
        dtype: int64
        �nsa�
        The nanoseconds of the datetime.

        Examples
        --------
        >>> datetime_series = pd.Series(
        ...     pd.date_range("2000-01-01", periods=3, freq="ns")
        ... )
        >>> datetime_series
        0   2000-01-01 00:00:00.000000000
        1   2000-01-01 00:00:00.000000001
        2   2000-01-01 00:00:00.000000002
        dtype: datetime64[ns]
        >>> datetime_series.dt.nanosecond
        0       0
        1       1
        2       2
        dtype: int64
        a�
    The day of the week with Monday=0, Sunday=6.

    Return the day of the week. It is assumed the week starts on
    Monday, which is denoted by 0 and ends on Sunday which is denoted
    by 6. This method is available on both Series with datetime
    values (using the `dt` accessor) or DatetimeIndex.

    Returns
    -------
    Series or Index
        Containing integers indicating the day number.

    See Also
    --------
    Series.dt.dayofweek : Alias.
    Series.dt.weekday : Alias.
    Series.dt.day_name : Returns the name of the day of the week.

    Examples
    --------
    >>> s = pd.date_range('2016-12-31', '2017-01-08', freq='D').to_series()
    >>> s.dt.dayofweek
    2016-12-31    5
    2017-01-01    6
    2017-01-02    0
    2017-01-03    1
    2017-01-04    2
    2017-01-05    3
    2017-01-06    4
    2017-01-07    5
    2017-01-08    6
    Freq: D, dtype: int64
    ZdowZdoyz.
        The ordinal day of the year.
        �qz*
        The quarter of the date.
        Zdimz2
        The number of days in the month.
        a�
        Indicates whether the date is the {first_or_last} day of the month.

        Returns
        -------
        Series or array
            For Series, returns a Series with boolean values.
            For DatetimeIndex, returns a boolean array.

        See Also
        --------
        is_month_start : Return a boolean indicating whether the date
            is the first day of the month.
        is_month_end : Return a boolean indicating whether the date
            is the last day of the month.

        Examples
        --------
        This method is available on Series with datetime values under
        the ``.dt`` accessor, and directly on DatetimeIndex.

        >>> s = pd.Series(pd.date_range("2018-02-27", periods=3))
        >>> s
        0   2018-02-27
        1   2018-02-28
        2   2018-03-01
        dtype: datetime64[ns]
        >>> s.dt.is_month_start
        0    False
        1    False
        2    True
        dtype: bool
        >>> s.dt.is_month_end
        0    False
        1    True
        2    False
        dtype: bool

        >>> idx = pd.date_range("2018-02-27", periods=3)
        >>> idx.is_month_start
        array([False, False, True])
        >>> idx.is_month_end
        array([False, True, False])
    �first)Z
first_or_last�lasta�
        Indicator for whether the date is the first day of a quarter.

        Returns
        -------
        is_quarter_start : Series or DatetimeIndex
            The same type as the original data with boolean values. Series will
            have the same name and index. DatetimeIndex will have the same
            name.

        See Also
        --------
        quarter : Return the quarter of the date.
        is_quarter_end : Similar property for indicating the quarter start.

        Examples
        --------
        This method is available on Series with datetime values under
        the ``.dt`` accessor, and directly on DatetimeIndex.

        >>> df = pd.DataFrame({'dates': pd.date_range("2017-03-30",
        ...                   periods=4)})
        >>> df.assign(quarter=df.dates.dt.quarter,
        ...           is_quarter_start=df.dates.dt.is_quarter_start)
               dates  quarter  is_quarter_start
        0 2017-03-30        1             False
        1 2017-03-31        1             False
        2 2017-04-01        2              True
        3 2017-04-02        2             False

        >>> idx = pd.date_range('2017-03-30', periods=4)
        >>> idx
        DatetimeIndex(['2017-03-30', '2017-03-31', '2017-04-01', '2017-04-02'],
                      dtype='datetime64[ns]', freq='D')

        >>> idx.is_quarter_start
        array([False, False,  True, False])
        a�
        Indicator for whether the date is the last day of a quarter.

        Returns
        -------
        is_quarter_end : Series or DatetimeIndex
            The same type as the original data with boolean values. Series will
            have the same name and index. DatetimeIndex will have the same
            name.

        See Also
        --------
        quarter : Return the quarter of the date.
        is_quarter_start : Similar property indicating the quarter start.

        Examples
        --------
        This method is available on Series with datetime values under
        the ``.dt`` accessor, and directly on DatetimeIndex.

        >>> df = pd.DataFrame({'dates': pd.date_range("2017-03-30",
        ...                    periods=4)})
        >>> df.assign(quarter=df.dates.dt.quarter,
        ...           is_quarter_end=df.dates.dt.is_quarter_end)
               dates  quarter    is_quarter_end
        0 2017-03-30        1             False
        1 2017-03-31        1              True
        2 2017-04-01        2             False
        3 2017-04-02        2             False

        >>> idx = pd.date_range('2017-03-30', periods=4)
        >>> idx
        DatetimeIndex(['2017-03-30', '2017-03-31', '2017-04-01', '2017-04-02'],
                      dtype='datetime64[ns]', freq='D')

        >>> idx.is_quarter_end
        array([False,  True, False, False])
        a~
        Indicate whether the date is the first day of a year.

        Returns
        -------
        Series or DatetimeIndex
            The same type as the original data with boolean values. Series will
            have the same name and index. DatetimeIndex will have the same
            name.

        See Also
        --------
        is_year_end : Similar property indicating the last day of the year.

        Examples
        --------
        This method is available on Series with datetime values under
        the ``.dt`` accessor, and directly on DatetimeIndex.

        >>> dates = pd.Series(pd.date_range("2017-12-30", periods=3))
        >>> dates
        0   2017-12-30
        1   2017-12-31
        2   2018-01-01
        dtype: datetime64[ns]

        >>> dates.dt.is_year_start
        0    False
        1    False
        2    True
        dtype: bool

        >>> idx = pd.date_range("2017-12-30", periods=3)
        >>> idx
        DatetimeIndex(['2017-12-30', '2017-12-31', '2018-01-01'],
                      dtype='datetime64[ns]', freq='D')

        >>> idx.is_year_start
        array([False, False,  True])
        a{
        Indicate whether the date is the last day of the year.

        Returns
        -------
        Series or DatetimeIndex
            The same type as the original data with boolean values. Series will
            have the same name and index. DatetimeIndex will have the same
            name.

        See Also
        --------
        is_year_start : Similar property indicating the start of the year.

        Examples
        --------
        This method is available on Series with datetime values under
        the ``.dt`` accessor, and directly on DatetimeIndex.

        >>> dates = pd.Series(pd.date_range("2017-12-30", periods=3))
        >>> dates
        0   2017-12-30
        1   2017-12-31
        2   2018-01-01
        dtype: datetime64[ns]

        >>> dates.dt.is_year_end
        0    False
        1     True
        2    False
        dtype: bool

        >>> idx = pd.date_range("2017-12-30", periods=3)
        >>> idx
        DatetimeIndex(['2017-12-30', '2017-12-31', '2018-01-01'],
                      dtype='datetime64[ns]', freq='D')

        >>> idx.is_year_end
        array([False,  True, False])
        a�
        Boolean indicator if the date belongs to a leap year.

        A leap year is a year, which has 366 days (instead of 365) including
        29th of February as an intercalary day.
        Leap years are years which are multiples of four with the exception
        of years divisible by 100 but not by 400.

        Returns
        -------
        Series or ndarray
             Booleans indicating if dates belong to a leap year.

        Examples
        --------
        This method is available on Series with datetime values under
        the ``.dt`` accessor, and directly on DatetimeIndex.

        >>> idx = pd.date_range("2012-01-01", "2015-01-01", freq="Y")
        >>> idx
        DatetimeIndex(['2012-12-31', '2013-12-31', '2014-12-31'],
                      dtype='datetime64[ns]', freq='A-DEC')
        >>> idx.is_leap_year
        array([ True, False, False])

        >>> dates_series = pd.Series(idx)
        >>> dates_series
        0   2012-12-31
        1   2013-12-31
        2   2014-12-31
        dtype: datetime64[ns]
        >>> dates_series.dt.is_leap_year
        0     True
        1    False
        2    False
        dtype: bool
        cCs�tj|j�}tj|j�}tj|j�}|dk}||d8<||d7<|tjd|dd�d|tj|d�tj|d	�tj|d
�d|j|jd|j	d
|j
d
d|jd
ddS)z�
        Convert Datetime Array to float64 ndarray of Julian Dates.
        0 Julian date is noon January 1, 4713 BC.
        https://en.wikipedia.org/wiki/Julian_day
        r�r{r;�i��im��di�g�C:AgN@g �@g��.Age��Ag8@)r��asarrayr^r<r_Zfixrur`rarbrkrl)rLr^r<r_Ztestarrr6r6r7�to_julian_date+s	N4zDatetimeArray.to_julian_date)NFr�r�N)F)N)T)r
N)r�r�)N)N)N)brQ�
__module__�__qualname__rRZ_typrr�rr�r�Z_recognized_scalarsrZ_is_recognized_dtyperCrIZ
_field_opsZ
_other_opsZ_datetimelike_opsZ_datetimelike_methodsZ__array_priority__rr�r)r�ryrr��classmethodr�rr�r�r�r�r��boolr�r�rSr�r5�setterrr�rr�r�r�r�r�r�r�r�r�r�r�rBrqrpr�rrror�rwrxrrnrmrrcrdrUr^r<r_r`rarbrkrlZ_dayofweek_docrfrergrhrirjZ
_is_month_docr�rWrXrYrZr[r\r]r�
__classcell__r6r6)r�r7rVusZ
#

H#^	

 
	L
5)
G
#
#/#,&&((%rVFr�cCs@d}t|�}tj|�}t|d�sFtj|�dkr6t|�}tj|�}d}nt|t	�rV|j
}t|t�rh|j�}t|d�rx|j
}t||�}t|t�r�|jdkr�td��|j}t||�\}}t|dd�}t|�s�t|�s�t|��rd}tj|dd�d	kr�|jtj�}nt|||d
�\}}	t||	�}|j}t|��r<t||j �}|j}
n�t!|��r�t|d|�}|jt"k�rht#j$|�}|dk	�r�tj|�}t%j&|j'd�||d
�}|j't"�}|jt"k�s�t(|j��|}
n6|�r�tj|�}|jt)k�r�|jtjdd�}|j't"�}
|�r�|
j*�}
t|
tj+��st(t,|
���|
jdk�s,t(|
j��t||�|
||fS)a�
    Parameters
    ----------
    data : list-like
    dtype : dtype, str, or None, default None
    copy : bool, default False
    tz : tzinfo, str, or None, default None
    dayfirst : bool, default False
    yearfirst : bool, default False
    ambiguous : str, bool, or arraylike, default 'raise'
        See pandas._libs.tslibs.tzconversion.tz_localize_to_utc.

    Returns
    -------
    result : numpy.ndarray
        The sequence converted to a numpy array with dtype ``datetime64[ns]``.
    tz : tzinfo or None
        Either the user-provided tzinfo or one inferred from the data.
    inferred_freq : Tick or None
        The inferred frequency of the sequence.

    Raises
    ------
    TypeError : PeriodDType data is passed
    Nr�rFrEr{z0Cannot create a DatetimeArray from a MultiIndex.)Zskipna�integer)r�r�r�r})r�)r�zM8[ns])-r�rr�r�r�r��listrrr,r�r+rrE�validate_tz_from_dtyper*Znlevelsr�r��maybe_convert_dtyper�r#r&r%rZinfer_dtyper�r��objects_to_datetime64ns�_maybe_infer_tzr�rr5rrr
Zensure_datetime64nsrr�r�r�rr�r�r�)r�r�r�r5r�r�r�r�Z
data_dtype�inferred_tzrNr6r6r7r�Psp#



















r�cCs�|d	kst�tj|dtjd�}ytj||||||d�\}}Wn\tk
r�}	z@ytj|�\}
}|
j	d�|fStt
fk
r�|	�YnXWYdd}	~	XnX|dk	r�|j	d�|fSt|�r�||fSt|�r�|r�||fSt
|��nt
|��dS)
a�
    Convert data to array of timestamps.

    Parameters
    ----------
    data : np.ndarray[object]
    dayfirst : bool
    yearfirst : bool
    utc : bool, default False
        Whether to convert timezone-aware timestamps to UTC.
    errors : {'raise', 'ignore', 'coerce'}
    allow_object : bool
        Whether to return an object-dtype ndarray instead of raising if the
        data contains more than one timezone.

    Returns
    -------
    result : ndarray
        np.int64 dtype if returned values represent UTC timestamps
        np.datetime64[ns] if returned values represent wall times
        object if mixed timezones
    inferred_tz : tzinfo or None

    Raises
    ------
    ValueError : if data cannot be converted to datetimes
    r��ignore�coerceF)r�r�)�errors�utcr�r��require_iso8601r}N)r�r"r#)
r�r�r��object_r	Zarray_to_datetimer�r
Zdatetime_to_datetime64r�r�rr#)r�r�r�r%r$r&Zallow_objectrNZ	tz_parsed�erMr6r6r7r�s2$
rcCs�t|d�s||fSt|j�r,|jt�}d}n�t|j�s@t|j�rTtd|j�d���nbt|j�rhtd��nNt	|j�r�|j
j|jt
d�j}d}n*t|j�r�t|j�r�tj|tjd�}d}||fS)aN
    Convert data based on dtype conventions, issuing deprecation warnings
    or errors where appropriate.

    Parameters
    ----------
    data : np.ndarray or pd.Index
    copy : bool

    Returns
    -------
    data : np.ndarray or pd.Index
    copy : bool

    Raises
    ------
    TypeError : PeriodDType data is passed
    r�Fzdtype z& cannot be converted to datetime64[ns]zFPassing PeriodDtype data is invalid. Use `data.to_timestamp()` instead)r=)r�)r�r"r�r�rr'rr�r$r�
categoriesZtake�codesr
r�r!rr�r�r')r�r�r6r6r7r*s"




r)r5r!r�cCs<|dkr|}n*|dkrn tj||�s8td|�d|����|S)aV
    If a timezone is inferred from data, check that it is compatible with
    the user-provided timezone, if any.

    Parameters
    ----------
    tz : tzinfo or None
    inferred_tz : tzinfo or None

    Returns
    -------
    tz : tzinfo or None

    Raises
    ------
    TypeError : if both timezones are present but do not match
    Nzdata is already tz-aware z, unable to set specified tz: )rr�r�)r5r!r6r6r7r gsr cCsf|dk	rbt|�}t|tjd��r,d}t|��t|tj�r@|tksRt|tjtf�rbtd|�d���|S)a�
    Check that a dtype, if passed, represents either a numpy datetime64[ns]
    dtype or a pandas DatetimeTZDtype.

    Parameters
    ----------
    dtype : object

    Returns
    -------
    dtype : None, numpy.dtype, or DatetimeTZDtype

    Raises
    ------
    ValueError : invalid dtype

    Notes
    -----
    Unlike validate_tz_from_dtype, this does _not_ allow non-existent
    tz errors to go through
    NZM8zhPassing in 'datetime64' dtype with no precision is not allowed. Please pass in 'datetime64[ns]' instead.zUnexpected value for 'dtype': 'z0'. Must be 'datetime64[ns]' or DatetimeTZDtype'.)r(r r�r�r�rrr))r�r�r6r6r7r��sr�)r5r�cCs�|dk	r�t|t�r6ytj|�}Wntk
r4YnXt|dd�}|dk	rl|dk	rhtj||�rhtd��|}|dk	r�t	|�r�|dk	r�tj||�r�td��|S)aU
    If the given dtype is a DatetimeTZDtype, extract the implied
    tzinfo object from it and check that it does not conflict with the given
    tz.

    Parameters
    ----------
    dtype : dtype, str
    tz : None, tzinfo

    Returns
    -------
    tz : consensus tzinfo

    Raises
    ------
    ValueError : on tzinfo mismatch
    Nr5z-cannot supply both a tz and a dtype with a tzzHcannot supply both a tz and a timezone-naive dtype (i.e. datetime64[ns]))
r�strr)Zconstruct_from_stringr�r�rr�r�r)r�r5r�r6r6r7r�s 
r)r9r:r5r�cCs�ytj||�}Wn,tk
r<}ztd�|�WYdd}~XnXtj|�}tj|�}|dk	rx|dk	rxtj||�s�td��n|dk	r�|}|S)a�
    If a timezone is not explicitly given via `tz`, see if one can
    be inferred from the `start` and `end` endpoints.  If more than one
    of these inputs provides a timezone, require that they all agree.

    Parameters
    ----------
    start : Timestamp
    end : Timestamp
    tz : tzinfo or None

    Returns
    -------
    tz : tzinfo or None

    Raises
    ------
    TypeError : if start and end timezones do not agree
    z>Start and end cannot both be tz-aware with different timezonesNz0Inferred time zone not equal to passed time zone)rZinfer_tzinfor�r�r�r�)r9r:r5r!�errr6r6r7r��s


r�)r9r:rrcCsbd}|dk	r.|r|j�}d}n|o,|j�tk}|dk	rX|rH|j�}d}n|oV|j�tk}|||fS)NT)rrr�	_midnight)r9r:rrr�r6r6r7r�	sr�cCsV|dkrR|dk	rR|dkr|nd}||dd�}t|t�s>|dkrF||d<|jf|�}|S)a
    Localize a start or end Timestamp to the timezone of the corresponding
    start or end Timestamp

    Parameters
    ----------
    ts : start or end Timestamp to potentially localize
    is_none : argument that should be None
    is_not_none : argument that should not be None
    freq : Tick, DateOffset, or None
    tz : str, timezone object or None
    ambiguous: str, localization behavior for ambiguous times
    nonexistent: str, localization behavior for nonexistent times

    Returns
    -------
    ts : Timestamp
    Nr~F)r�r�r5r5)rr4rp)�tsZis_noneZis_not_nonerEr5r�r�Z
localize_argsr6r6r7r�!	sr�ccsjt|�}t|�}|tk	r|nd}t|�}|tk	r4|nd}|rT|j|�rT|j|�}n|rn|j|�rn|j|�}|dkr�||kr�|jdkr�d}d}|dkr�||d|}|dkr�||d|}|}|jdk�rx�||k�r|V||kr�P|j|�}||k�rtd|�d���|}q�WnLxJ||k�rd|V||k�r8P|j|�}||k�r\td|�d���|}�qWdS)a�
    Generates a sequence of dates corresponding to the specified time
    offset. Similar to dateutil.rrule except uses pandas DateOffset
    objects to represent time increments.

    Parameters
    ----------
    start : datetime, (default None)
    end : datetime, (default None)
    periods : int, (default None)
    offset : DateOffset, (default BDay())

    Notes
    -----
    * This method is faster for generating weekdays than dateutil.rrule
    * At least two of (start, end, periods) must be specified.
    * If both start and end are specified, the returned dates will
    satisfy start <= date <= end.

    Returns
    -------
    dates : generator object
    Nrr{zOffset z did not increment datez did not decrement date)	rrr
Zis_on_offsetZrollforward�rollback�n�applyr�)r9r:r�r��curZ	next_dater6r6r7r�B	sD






r�)N)NFNFFr�)Fr�FF)ZrrrrZtypingrrr�Znumpyr�Zpandas._libsrr	Zpandas._libs.tslibsr
rrr
rrrrrrrrrZ
pandas.errorsrZpandas.core.dtypes.commonrrrrrrrrr r!r"r#r$r%r&r'r(Zpandas.core.dtypes.dtypesr)Zpandas.core.dtypes.genericr*r+r,Zpandas.core.dtypes.missingr-Zpandas.core.algorithmsr.r�r/r�Zpandas.core.arrays._rangesr0Zpandas.core.common�core�commonr�Zpandas.tseries.frequenciesr1Zpandas.tseries.offsetsr2r3r4r-r8rUr�ZTimelikeOpsZDatelikeOpsrVr�rrr r�rr�rr�r�r�r6r6r6r7�<module>sl<L

(j

L>*0
*!