Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
1576 views


9�W���@sdZddlmZddlmZddlmZmZmZmZm	Z	m
Z
mZddlZddl
m
Z
dd	d
ddd
dgiZdddddgZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zdd�ZdS)z�
Customisable progressbar decorator for iterators.
Includes a default (x)range iterator printing to stderr.

Usage:
  >>> from tqdm import trange[, tqdm]
  >>> for i in trange(10): #same as: for i in tqdm(xrange(10))
  ...     ...
�)�absolute_import)�division�)�_supports_unicode�_environ_cols_wrapper�_range�_unich�
_term_move_up�_unicode�WeakSetN)�timezgithub.com/ZnoamraphZobiwanusZkmikeZhadimZ	casperdclZlrq3000�tqdm�trange�
TqdmTypeError�TqdmKeyError�TqdmDeprecationWarningc@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�)lib/python3.5/site-packages/tqdm/_tqdm.pyrsc@seZdZdS)rN)rrrrrrrrscs%eZdZd�fdd�Z�S)rNcsM|dk	r-|dt|�j�d�ntt|�j|||�dS)Nz
TqdmDeprecationWarning: �
)�str�rstrip�superr�__init__)�self�msg�fp_write�a�k)�	__class__rrr%s!zTqdmDeprecationWarning.__init__)rrrrrr)r!rr#sc@seZdZdZeddd��Zedd��Zedd��Zed	dd
dd
d	d	dd
��Zdd�Z	e
d	dd��Ze
dd��Ze
e
jddd��Ze
dd��Zd	d	d	de
jd	ddd	d	d
dd
d
dd	dd	d
dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;d<�Z d=d>�Z!d?d@�Z"d	dAdB�Z#dCdD�Z$d
dEdF�Z%dGdH�Z&d	S)Ir
z�
    Decorate an iterable object, returning an iterator which acts exactly
    like the original iterable, but prints a dynamically updating
    progressbar every time a value is requested.
    �cCs�x�ddddddddgD]�}t|�d	kr�t|�d
kr�t|�dkrpdj|�||Sd
j|�||Sdj|�||S|d}qWdj|�|S)a~
        Formats a number (greater than unity) with SI Order of Magnitude
        prefixes.

        Parameters
        ----------
        num  : float
            Number ( >= 1) to format.
        suffix  : str, optional
            Post-postfix [default: ''].

        Returns
        -------
        out  : str
            Number with Order of Magnitude SI unit postfix.
        r"�K�M�G�T�P�E�Zg�����?�@g������X@g=
ףp�#@z{0:1.2f}z{0:2.1f}z{0:3.0f}g@�@z	{0:3.1f}Y)�abs�format)Znum�suffix�unitrrr�
format_sizeof2s%ztqdm.format_sizeofcCs]tt|�d�\}}t|d�\}}|rIdj|||�Sdj||�SdS)z�
        Formats a number of seconds as a clock time, [H:]MM:SS

        Parameters
        ----------
        t  : int
            Number of seconds.
        Returns
        -------
        out  : str
            [H:]MM:SS
        �<z{0:d}:{1:02d}:{2:02d}z{0:02d}:{1:02d}N)�divmod�intr+)�tZmins�s�h�mrrr�format_intervalNs
ztqdm.format_intervalcsU|�t�ddd�����fdd��dg���fdd�}|S)	z�
        Manage the printing and in-place updating of a line of characters.
        Note that if the string is longer than a line, then in-place
        updating may not work (it will print a new line at each refresh).
        �flushcSsdS)Nrrrrr�<lambda>ksz%tqdm.status_printer.<locals>.<lambda>cs�jt|����dS)N)�writer
)r3)�fp�fp_flushrrrmsz%tqdm.status_printer.<locals>.fp_writercsAt|�}�d|dt�d|d��|�d<dS)N�
� r)�len�max)r3Zlen_s)r�last_lenrr�print_statusss'z)tqdm.status_printer.<locals>.print_status)�getattr)�filerAr)r:r;rr@r�status_printercs	ztqdm.status_printerNF�itc
Cs
|r||krd}tj}
|
|�}|dkrI|rI||}|re|dkred|nd}tj}
|r�|r�|
|r�|n|�q�dj|r�|n|�nd|r�dn|d|r�|nd}|r
|
|�}|r|
|�nd}nt|�}t|�}|r�||}|d}|rV|
|||�nd}|rh|ndd	j|�}d
j|||||�}|dkr�|dd$�|dd�S|	r�d|d
|d|d|d|d|dkr�|n|d|d|r*|r|
|�q-dj|�nd|dd|d|d|d|d|d|rb|ndi}d|	kr�|	jd�\}}|j|�}|j|�}n
|	j|�S|r�td|t|�t|��nd}|r;tt	||d�d�\}}d|}|r2t
d|�nd}nOtt	||d �d �\}}td!�|}|r�td"|�nd}||kr�||dt||dd�}n|dt||d�}|||S|r�|ndd#j||||�SdS)%a�
        Return a string-based progress bar given some parameters

        Parameters
        ----------
        n  : int
            Number of finished iterations.
        total  : int
            The expected total number of iterations. If meaningless (), only
            basic progress statistics are displayed (no ETA).
        elapsed  : float
            Number of seconds passed since start.
        ncols  : int, optional
            The width of the entire output message. If specified,
            dynamically resizes the progress meter to stay within this bound
            [default: None]. The fallback meter width is 10 for the progress
            bar + no limit for the iterations counter and statistics. If 0,
            will not print any meter (only stats).
        prefix  : str, optional
            Prefix message (included in total width) [default: ''].
        ascii  : bool, optional
            If not set, use unicode (smooth blocks) to fill the meter
            [default: False]. The fallback is to use ASCII characters
            (1-9 #).
        unit  : str, optional
            The iteration unit [default: 'it'].
        unit_scale  : bool, optional
            If set, the number of iterations will printed with an
            appropriate SI metric prefix (K = 10^3, M = 10^6, etc.)
            [default: False].
        rate  : float, optional
            Manual override for iteration rate.
            If [default: None], uses n/elapsed.
        bar_format  : str, optional
            Specify a custom bar string formatting. May impact performance.
            [default: '{l_bar}{bar}{r_bar}'], where l_bar is
            '{desc}{percentage:3.0f}%|' and r_bar is
            '| {n_fmt}/{total_fmt} [{elapsed_str}<{remaining_str}, {rate_fmt}]'
            Possible vars: bar, n, n_fmt, total, total_fmt, percentage,
            rate, rate_fmt, elapsed, remaining, l_bar, r_bar, desc.

        Returns
        -------
        out  : Formatted meter and stats, ready to display.
        Nrz{0:5.2f}�?r3�/�dr"z
{0:3.0f}%|z| {0}/{1} [{2}<{3}, {4}]r�n�n_fmt�total�	total_fmt�
percentage�rateZ
rate_noinvZrate_noinv_fmtz/s�rate_fmt�elapsedZ	remaining�l_bar�r_bar�descz{bar}�
�#�0r=�i�%i�%z{0}{1} [{2}, {3}]�����)r
r6r.r+r�splitr?r>r0r1�chrr)rIrKrP�ncols�prefix�asciir-�
unit_scalerN�
bar_formatr6Zelapsed_strZinv_rater.rOrJrLZfracrMZ
remaining_strrQrRZbar_argsZ
l_bar_userZ
r_bar_userZN_BARSZ
bar_lengthZfrac_bar_lengthZbarZfrac_barZfull_barrrr�format_meterys�3	
"	i

 2
) 
	#ztqdm.format_metercOs>tj|�}d|jkr*t�|_|jj|�|S)N�
_instances)�object�__new__�__dict__rra�add)�cls�args�kwargs�instancerrrrcs
ztqdm.__new__csmy(t�fdd�|jD��dSWn>tk
rh}zdt|�krSdS�WYdd}~XnXdS)z Skips specified instance c3s$|]}|�k	r|jVqdS)N)�pos)�.0�inst)rirr�	<genexpr>,sz%tqdm._get_free_pos.<locals>.<genexpr>rzarg is an empty sequencerN)r?ra�
ValueErrorr)rfri�er)rir�
_get_free_pos(s	ztqdm._get_free_poscCsbyI|jj|�x2|jD]'}|j|jkr|jd8_qWWntk
r]YnXdS)zs
        Remove from list and reposition other bars
        so that newer bars won't overlap previous bars
        rN)ra�removerj�KeyError)rfrirlrrr�_decr_instances3s
ztqdm._decr_instancesrcCs�|}g}xbt|dg�D]N}|j|ksVtdd�||jfD��r|j�|j|�qW|j|�|j|�x|D]}|j�q�WdS)zF
        Print a message via tqdm (without overlap with bars)
        racss'|]}|tjtjfkVqdS)N)�sys�stdout�stderr)rk�frrrrmNsztqdm.write.<locals>.<genexpr>N)rBr:�all�clear�appendr9�refresh)rfr3rC�endr:Zinst_clearedrlrrrr9As



z
tqdm.writec
sIddlm}ddlm�ddlm}ddlm}ddlm}ddlm}ddl	m
}�jd	d
�g�d�����fdd
�}	|	��_|	�|_|	d��_
|	d�|_
|	�|_|	�|_|	d�|_|	�|_|	�|_|	�|_|	d�|_|	d�|_d
S)a&
        Registers the given `tqdm` class with
            pandas.core.
            ( frame.DataFrame
            | series.Series
            | groupby.DataFrameGroupBy
            | groupby.SeriesGroupBy
            ).progress_apply

        A new instance will be create every time `progress_apply` is called,
        and each instance will automatically close() upon completion.

        Parameters
        ----------
        targs, tkwargs  : arguments for the tqdm instance

        Examples
        --------
        >>> import pandas as pd
        >>> import numpy as np
        >>> from tqdm import tqdm, tqdm_gui
        >>>
        >>> df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
        >>> tqdm.pandas(ncols=50)  # can use tqdm_gui, optional kwargs, etc
        >>> # Now you can use `progress_apply` instead of `apply`
        >>> df.groupby(0).progress_apply(lambda x: x**2)

        References
        ----------
        https://stackoverflow.com/questions/18603270/
        progress-indicator-during-pandas-operations-python
        r)�	DataFrame)�Series)�DataFrameGroupBy)�
SeriesGroupBy)�GroupBy)�PanelGroupBy)�Panel�deprecated_tNZapplycs%������fdd�}|S)Ncs�t|dd�}|dkrOt|��r9t|�n|jt|�}n
|d7}�ddk	r��d�d�d<n��d|�����fdd�}t|��|||�}�j�|S)aZ
                Parameters
                ----------
                df  : (DataFrame|Series)[GroupBy]
                    Data (may be grouped).
                func  : function
                    To be applied on the (grouped) data.
                *args, *kwargs  : optional
                    Transmitted to `df.apply()`.
                ZngroupsNrrrKcs�j��||�S)N)�update)rgrh)�funcr2rr�wrapper�s
zDtqdm.pandas.<locals>.inner_generator.<locals>.inner.<locals>.wrapper)rB�
isinstancer>�size�close)Zdfr�rgrhrKr��result)r~r��df_function�targs�tclass�tkwargs)r�r2r�inner�s



z3tqdm.pandas.<locals>.inner_generator.<locals>.innerr)r�r�)r~r�r�r�r�)r�r�inner_generator�s!&z$tqdm.pandas.<locals>.inner_generator�mapZapplymapZ	aggregateZ	transform)Zpandas.core.framer}Zpandas.core.seriesr~Zpandas.core.groupbyrr�r�r��pandasr��popZprogress_applyZprogress_mapZprogress_applymapZprogress_aggregateZprogress_transform)
r�r�r�r}rr�r�r�r�r�r)r~r�r�r�r�rr�Zs*"!+ztqdm.pandasTg�������?g$@g333333�?rcKs�|r>||_||_|j|�|_|jj|�dS|r�d|_|j|�|_|jj|�d|kr�tddt|dtj	j
��ntdt|���|dkr�|dk	r�yt
|�}Wnttfk
r�d}YnX|dkr"|tj	tjfks(|rU|rFt�}||�}nt�|�}|	dkrpd}	d}nd	}|dkr�d}|dkr�d}|
dkr�t|�}
|r�|
r�t|�}|dkr�d}||_|r�|d
nd|_||_||_||_||_||_||_|	|_||_|
|_||_||_|
|_||_ ||_!||_"d|_#t$|_%||_&||_'||_(|dkr�|j|�n||_|so|j)|j�|_*|jr|j+|j�|j*|j,|j(|d|r6||�n||j|
||
d|�
�|jro|j+|j�|j%�|_-|_.dS)a�
        Parameters
        ----------
        iterable  : iterable, optional
            Iterable to decorate with a progressbar.
            Leave blank to manually manage the updates.
        desc  : str, optional
            Prefix for the progressbar.
        total  : int, optional
            The number of expected iterations. If unspecified,
            len(iterable) is used if possible. As a last resort, only basic
            progress statistics are displayed (no ETA, no progressbar).
            If `gui` is True and this parameter needs subsequent updating,
            specify an initial arbitrary large positive integer,
            e.g. int(9e9).
        leave  : bool, optional
            If [default: True], keeps all traces of the progressbar
            upon termination of iteration.
        file  : `io.TextIOWrapper` or `io.StringIO`, optional
            Specifies where to output the progress messages
            [default: sys.stderr]. Uses `file.write(str)` and `file.flush()`
            methods.
        ncols  : int, optional
            The width of the entire output message. If specified,
            dynamically resizes the progressbar to stay within this bound.
            If unspecified, attempts to use environment width. The
            fallback is a meter width of 10 and no limit for the counter and
            statistics. If 0, will not print any meter (only stats).
        mininterval  : float, optional
            Minimum progress update interval, in seconds [default: 0.1].
        maxinterval  : float, optional
            Maximum progress update interval, in seconds [default: 10.0].
        miniters  : int, optional
            Minimum progress update interval, in iterations.
            If specified, will set `mininterval` to 0.
        ascii  : bool, optional
            If unspecified or False, use unicode (smooth blocks) to fill
            the meter. The fallback is to use ASCII characters `1-9 #`.
        disable  : bool, optional
            Whether to disable the entire progressbar wrapper
            [default: False].
        unit  : str, optional
            String that will be used to define the unit of each iteration
            [default: it].
        unit_scale  : bool, optional
            If set, the number of iterations will be reduced/scaled
            automatically and a metric prefix following the
            International System of Units standard will be added
            (kilo, mega, etc.) [default: False].
        dynamic_ncols  : bool, optional
            If set, constantly alters `ncols` to the environment (allowing
            for window resizes) [default: False].
        smoothing  : float, optional
            Exponential moving average smoothing factor for speed estimates
            (ignored in GUI mode). Ranges from 0 (average speed) to 1
            (current/instantaneous speed) [default: 0.3].
        bar_format  : str, optional
            Specify a custom bar string formatting. May impact performance.
            If unspecified, will use '{l_bar}{bar}{r_bar}', where l_bar is
            '{desc}{percentage:3.0f}%|' and r_bar is
            '| {n_fmt}/{total_fmt} [{elapsed_str}<{remaining_str}, {rate_fmt}]'
            Possible vars: bar, n, n_fmt, total, total_fmt, percentage,
            rate, rate_fmt, elapsed, remaining, l_bar, r_bar, desc.
        initial  : int, optional
            The initial counter value. Useful when restarting a progress
            bar [default: 0].
        position  : int, optional
            Specify the line offset to print this bar (starting from 0)
            Automatic if unspecified.
            Useful to manage multiple bars at once (eg, from threads).
        gui  : bool, optional
            WARNING: internal parameter - do not use.
            Use tqdm_gui(...) instead. If set, will attempt to use
            matplotlib animations for a graphical output [default: False].

        Returns
        -------
        out  : decorated iterator.
        NT�nestedzO`nested` is deprecated and automated. Use position instead for manual control.
rr9zUnknown argument(s): rFz: r")/�iterable�disablerprjrarqrrBrtrvr9rrr>�	TypeError�AttributeErrorrurrr
rSrK�leaver:r[�mininterval�maxinterval�miniters�dynamic_minitersr]r-r^�gui�
dynamic_ncols�	smoothing�avg_timer�_timer_�last_print_nrIrD�sp�movetor`�start_t�last_print_t)rr�rSrKr�rCr[r�r�r�r]r�r-r^r�r�r_�initialZpositionr�rhr�rrrr�s�U			0$		

																					$		z
tqdm.__init__cCsE|jdk	r>t|jd�r1|jjdqDt|j�S|jS)N�shaper)r��hasattrr�r>rK)rrrr�__len__xs>ztqdm.__len__cCs|S)Nr)rrrr�	__enter__}sztqdm.__enter__cGs|j�dS)NF)r�)r�excrrr�__exit__�s
z
tqdm.__exit__cCs|j�dS)N)r�)rrrr�__del__�sztqdm.__del__cCs`|j|j|jt�|j|j|j|j|j|j	|j
rSd|j
nd|j�
S)Nr)r`rIrKrr�r[rSr]r-r^r�r_)rrrr�__repr__�s

z
tqdm.__repr__cCs|j|jkS)N)rj)r�otherrrr�__lt__�sztqdm.__lt__cCs||kp||kS)Nr)rr�rrr�__le__�sztqdm.__le__cCs|j|jkS)N)rj)rr�rrr�__eq__�sztqdm.__eq__cCs||kS)Nr)rr�rrr�__ne__�sztqdm.__ne__cCs||kS)Nr)rr�rrr�__gt__�sztqdm.__gt__cCs||kS)Nr)rr�rrr�__ge__�sztqdm.__ge__cCs
t|�S)N)�id)rrrr�__hash__�sz
tqdm.__hash__ccs�|j}|jr+x�|D]}|VqWn�|j}|j}|j}|j}|j}|j}|j}	|j	}
|j
}|j}|j}
|j
}|j}|j}|j}|j}|j}|j}y
|j}Wn9tk
rtddt|jdtjj���YnXx�|D]�}|V|d7}||
|kr|�|}||kr|�}||
}||}|r�|r�|dkr�||n|||d||}|jr�|j|j�||||j||r�||j�n||j|
||	|rd|nd|�
�|jr=|j|j�|r�|rf||krf|||}nC|r�|r�||||d||}n||d||}||_
|_}
||_}qW|
|_||_
|j �dS)z8 Backward-compatibility to use: for x in tqdm(iterable) z<Please use `tqdm_gui(...)` instead of `tqdm(..., gui=True)`
rr9rN)!r�r�r[r�r�r�r�r-r^r]r�r�r�rIr�r�r�r_r�r`r�r�rrBr:rtrvr9rjr�rKrSr�)rr��objr[r�r�r�r�r-r^r]r�r�r�rIr�r�r�r_r�r`r��delta_t�cur_t�delta_itrPrrr�__iter__�s|		
																		

)


	

		!		z
tqdm.__iter__rcCs�|jr
dS|dkr.tdj|���|j|7_|j|j|jkr�|j�|j}||jkr�|j�}|j|j}||j	}|j
r�|r�|jdkr�||n |j
||d|j
|j|_t|d�s%t
ddt|jdtjj���|jr>|j|j�|j|j|j|j||jrt|j|j�n|j|j|j|j|j|jr�d|jnd|j�
�|jr�|j|j�|jrn|j r
||j kr
|j|j ||_na|jrL|rL|j
||j|d|j
|j|_n"|j
|d|j
|j|_|j|_||_dS)	at
        Manually update the progress bar, useful for streams
        such as reading files.
        E.g.:
        >>> t = tqdm(total=filesize) # Initialise
        >>> for current_buffer in stream:
        ...    ...
        ...    t.update(len(current_buffer))
        >>> t.close()
        The last line is highly recommended, but possibly not necessary if
        `t.update()` will be called in such a way that `filesize` will be
        exactly reached and printed.

        Parameters
        ----------
        n  : int
            Increment to add to the internal counter of iterations
            [default: 1].
        Nrzn ({0}) cannot be negativerr�z<Please use `tqdm_gui(...)` instead of `tqdm(..., gui=True)`
rr9)!r�rnr+rIr�r�r�r�r�r�r�r�r�rrBr:rtrvr9rjr�r�r`rKr�r[rSr]r-r^r_r�r�)rrIr�r�r�rPrrrr�sN	
$	
		
ztqdm.updatecs��jr
dSd�_�j}�j��t�d�s?dS�fdd�}y|d�Wn>tk
r�}zdt|�kr�dS�WYdd}~XnX|r��j|��jri�j�j	krE�j
�}�j�j�j	�j
|�j�jr�j�j�n�j�j�j�j�jd�j�
�|r\�j|�q�|d�n.�jd�|r��j|�n
|d	�dS)
zE
        Cleanup and (if leave=False) close the progressbar.
        NTr�cs�jjt|��dS)N)r:r9r
)r3)rrrrhsztqdm.close.<locals>.fp_writer"�closedrr<)r�rjrsr�rnrr�r�r�rIr�r�r`rKr�r�r:r[rSr]r-r^r_)rrjrror�r)rrr�Us@			

	


z
tqdm.closecCs/|j�}|j||j7_||_dS)z:
        Restart tqdm timer from last print time.
        N)r�r�r�)rr�rrr�unpause�sztqdm.unpausecCs|r|dnd|_dS)z=
        Set/modify description of the progress bar.
        z: r"N)rS)rrSrrr�set_description�sztqdm.set_descriptioncCs*|jjtd|t�|��dS)Nr)r:r9r
r	)rrIrrrr��sztqdm.movetocCsw|s|j|j�|jjd�|jjd|jrD|jnd�|jjd�|ss|j|j�dS)z+
        Clear current bar display
        r<r=rTN)r�rjr:r9r[)r�nomoverrrry�s&z
tqdm.clearcCsK|j|j�|jdd�|jj|j��|j|j�dS)z7
        Force refresh the display of this bar
        r�TN)r�rjryr:r9r�)rrrrr{�sztqdm.refresh)'rrr�__doc__�staticmethodr.r6rDr`rc�classmethodrprsrtrur9r�rvrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�ryr{rrrrr
,sT�

g	�`R5
cOstt|�|�S)zh
    A shortcut for tqdm(xrange(*args), **kwargs).
    On Python3+ range is used instead of xrange.
    )r
r)rgrhrrrr�s)r�Z
__future__rrZ_utilsrrrrr	r
rrtr�
__author__�__all__r�rrrr�	Exceptionrrbr
rrrrr�<module>	s"4	����