Файловый менеджер - Редактировать - /home/digitalm/venv/lib/python3.7/site-packages/pandas/core/tools/__pycache__/timedeltas.cpython-37.pyc
Назад
B �5�gT � @ s� d Z ddlZddlmZ ddlmZmZ ddlm Z m Z ddlmZ ddl mZmZ ddlmZ dd d�Zdd d�Zddd�ZdS )z timedelta support tools � N)�lib)�NaT�NaTType)� Timedelta�parse_timedelta_unit)�is_list_like)�ABCIndex� ABCSeries)�sequence_to_td64ns�raisec C s |dk rt |�}|dkr td��|dkr0td��| dkr<| S t| t�rjt| j||d�}| j|| j| jd�S t| t �r�t| ||| jd�S t| t j�r�| jd kr�t �| �} n>t| �r�t| d d�dkr�t| ||d�S t| d d�dkr�td��t| t��r|dk �rtd ��t| ||d�S )aU Convert argument to timedelta. Timedeltas are absolute differences in times, expressed in difference units (e.g. days, hours, minutes, seconds). This method converts an argument from a recognized timedelta format / value into a Timedelta type. Parameters ---------- arg : str, timedelta, list-like or Series The data to be converted to timedelta. .. deprecated:: 1.2 Strings with units 'M', 'Y' and 'y' do not represent unambiguous timedelta values and will be removed in a future version unit : str, optional Denotes the unit of the arg for numeric `arg`. Defaults to ``"ns"``. Possible values: * 'W' * 'D' / 'days' / 'day' * 'hours' / 'hour' / 'hr' / 'h' * 'm' / 'minute' / 'min' / 'minutes' / 'T' * 'S' / 'seconds' / 'sec' / 'second' * 'ms' / 'milliseconds' / 'millisecond' / 'milli' / 'millis' / 'L' * 'us' / 'microseconds' / 'microsecond' / 'micro' / 'micros' / 'U' * 'ns' / 'nanoseconds' / 'nano' / 'nanos' / 'nanosecond' / 'N' .. versionchanged:: 1.1.0 Must not be specified when `arg` context strings and ``errors="raise"``. errors : {'ignore', 'raise', 'coerce'}, default 'raise' - If 'raise', then invalid parsing will raise an exception. - If 'coerce', then invalid parsing will be set as NaT. - If 'ignore', then invalid parsing will return the input. Returns ------- timedelta64 or numpy.array of timedelta64 Output type returned if parsing succeeded. See Also -------- DataFrame.astype : Cast argument to a specified dtype. to_datetime : Convert argument to datetime. convert_dtypes : Convert dtypes. Notes ----- If the precision is higher than nanoseconds, the precision of the duration is truncated to nanoseconds for string inputs. Examples -------- Parsing a single string to a Timedelta: >>> pd.to_timedelta('1 days 06:05:01.00003') Timedelta('1 days 06:05:01.000030') >>> pd.to_timedelta('15.5us') Timedelta('0 days 00:00:00.000015500') Parsing a list or array of strings: >>> pd.to_timedelta(['1 days 06:05:01.00003', '15.5us', 'nan']) TimedeltaIndex(['1 days 06:05:01.000030', '0 days 00:00:00.000015500', NaT], dtype='timedelta64[ns]', freq=None) Converting numbers by specifying the `unit` keyword argument: >>> pd.to_timedelta(np.arange(5), unit='s') TimedeltaIndex(['0 days 00:00:00', '0 days 00:00:01', '0 days 00:00:02', '0 days 00:00:03', '0 days 00:00:04'], dtype='timedelta64[ns]', freq=None) >>> pd.to_timedelta(np.arange(5), unit='d') TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'], dtype='timedelta64[ns]', freq=None) N)�ignorer Zcoercez5errors must be one of 'ignore', 'raise', or 'coerce'.> �y�M�YzqUnits 'M', 'Y', and 'y' are no longer supported, as they do not represent unambiguous timedelta values durations.)�unit�errors)�index�name)r r r r �ndim� zBarg must be a string, timedelta, list, tuple, 1-d array, or Seriesz9unit must not be specified if the input is/contains a str)r � ValueError� isinstancer �_convert_listlikeZ_valuesZ_constructorr r r �npZndarrayr r Zitem_from_zerodimr �getattr� TypeError�str� _coerce_scalar_to_timedelta_type)�argr r �values� r �R/home/digitalm-up/venv/lib/python3.7/site-packages/pandas/core/tools/timedeltas.py�to_timedelta s0 S r"