U C^@szdZddlmZmZddlmZmZmZmZm Z m Z m Z m Z m Z mZmZmZmZmZmZmZddlmZddlmZddlZddlmZdd lmZddlZdd lm Z d d d ddddgiZ!ddddddddgZ"Gddde#Z$Gddde%Z&Gddde'Z(Gddde(e)Z*Gddde(e+Z,Gddde(e-Z.Gd d!d!e/Z0e01Gd"d#d#e/Z2Gd$ddeZ3d%dZ4dS)&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_importdivision)_supports_unicode_environ_cols_wrapper_range_unich _term_move_up_unicodeWeakSet _basestring _OrderedDict Comparable _is_ascii FormatReplacedisp_len disp_trimSimpleTextIOWrapperCallbackIOWrapper)TMonitor)contextmanagerN)Number)time)warnz github.com/ZnoamraphZobiwanusZkmikeZhadimZ casperdclZlrq3000tqdmtrange TqdmTypeError TqdmKeyError TqdmWarningTqdmExperimentalWarningTqdmDeprecationWarningTqdmMonitorWarningc@s eZdZdS)rN__name__ __module__ __qualname__r&r&*/tmp/pip-install-6_kvzl1k/tqdm/tqdm/std.pyr"sc@s eZdZdS)rNr"r&r&r&r'r&scs"eZdZdZdfdd ZZS)rzqbase class for all tqdm warnings. Used for non-external-code-breaking errors, such as garbled printing. NcsJ|dk r.|d|jjdt|dntt|j|f||dS)N : ) __class__r#strrstripsuperr__init__)selfmsgfp_writeakr*r&r'r./s zTqdmWarning.__init__)N)r#r$r%__doc__r. __classcell__r&r&r4r'r*sc@seZdZdZdS)rz(beta feature, unstable API and behaviourNr#r$r%r5r&r&r&r'r7sc@s eZdZdS)r Nr"r&r&r&r'r <sc@seZdZdZdS)r!z>tqdm monitor errors which do not affect external functionalityNr7r&r&r&r'r!Asc@sPeZdZdZddZddZddZdd Zd d Ze d d Z e ddZ dS)TqdmDefaultWriteLocka Provide a default write lock for thread and multiprocessing safety. Works only on platforms supporting `fork` (so Windows is excluded). You must initialise a `tqdm` or `TqdmDefaultWriteLock` instance before forking in order for the write lock to work. On Windows, you need to supply the lock from the parent to the children as an argument to joblib or the parallelism lib you use. cCs4||t|}dd|j|jfD|_dS)NcSsg|]}|dk r|qSNr&).0Zlkr&r&r' Usz1TqdmDefaultWriteLock.__init__..)create_mp_lockcreate_th_locktypemp_lockth_locklocks)r/clsr&r&r'r.OszTqdmDefaultWriteLock.__init__cOs|jD]}|j||qdSr9)rAacquire)r/r2r3lockr&r&r'rCWs zTqdmDefaultWriteLock.acquirecCs"|jdddD] }|qdS)N)rArelease)r/rDr&r&r'rF[szTqdmDefaultWriteLock.releasecCs |dSr9)rCr/r&r&r' __enter___szTqdmDefaultWriteLock.__enter__cGs |dSr9)rF)r/excr&r&r'__exit__bszTqdmDefaultWriteLock.__exit__cCsZt|dsVzddlm}||_Wn2tk r<d|_Yntk rTd|_YnXdS)Nr?r)RLock)hasattrmultiprocessingrKr? ImportErrorOSError)rBrKr&r&r'r<es    z#TqdmDefaultWriteLock.create_mp_lockcCs8t|ds4zt|_Wntk r2d|_YnXdS)Nr@)rLthrKr@rOrBr&r&r'r=ps  z#TqdmDefaultWriteLock.create_th_lockN) r#r$r%r5r.rCrFrHrJ classmethodr<r=r&r&r&r'r8Fs r8c @sJeZdZdZdZddeeedddZ dZ d e fd d Z d d Z dS)Bara `str.format`-able bar with format specifiers: `[width][type]` - `width` + unspecified (default): use `self.default_len` + `int >= 0`: overrides `self.default_len` + `int < 0`: subtract from `self.default_len` - `type` + `a`: ascii (`charset=self.ASCII` override) + `u`: unicode (`charset=self.UTF` override) + `b`: blank (`charset=" "` override) z 123456789# i%i%rEz cCsVd|krdks4ntdtddtdtd|}|dks@t||_||_||_dS)Nrrzclamping frac to range [0, 1] stacklevel)rrmaxminAssertionErrorfrac default_lencharset)r/r]r^r_r&r&r'r.s z Bar.__init__c Cs|r||d}zt|j|j|jd|}Wntk rF|j}YnX|dd}|rtt|}|dkrz||j7}q|j}n |j}|j}t |d}t t|j |||\}}|d|}||} ||kr|| |d||dS|S)NrE)r2ubrr) lowerdictASCIIUTFBLANKKeyErrorr_intr^lendivmodr]) r/ format_spec_typer_ZN_BARSZnsymsZ bar_lengthZfrac_bar_lengthbarZfrac_barr&r&r' __format__s4      zBar.__format__N) r#r$r%r5rdjoinmaprrangererfr.rnr&r&r&r'rSs   rSc@seZdZdZdZdZed]ddZedd Zed d Z ed^d dZ eddZ ed_ddZ ddZ ed`ddZeddZedaddZeedbddZed d!Zed"d#Zed$d%Zdcd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zed:d;Z dd?Z"dddAdBZ#dCdDZ$dedEdFZ%dfdGdHZ&dIdJZ'dgdKdLZ(dhdMdNZ)didOdPZ*djdQdRZ+dkdSdTZ,dUdVZ-edWdXZ.dldYdZZ/eedmd[d\Z0dS)nrz 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. rVNrUcCsdD]r}t|dkrnt|dkrXt|dkrBd|||Sd|||Sd|||S||}qd||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: '']. divisor : float, optional Divisor between prefixes [default: 1000]. Returns ------- out : str Number with Order of Magnitude SI unit postfix. )rUr3MGTPEZg<@gX@g= ףp#@z{0:1.2f}z{0:2.1f}z{0:3.0f}z {0:3.1f}Y)absformat)numsuffixdivisorunitr&r&r' format_sizeofs    ztqdm.format_sizeofcCsBtt|d\}}t|d\}}|r2d|||Sd||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)rjrhrz)tZminsshmr&r&r'format_intervals ztqdm.format_intervalcCs:d|dddd}t|}t|t|kr6|S|S)z Intelligent scientific notation (.3g). Parameters ---------- n : int or float or Numeric A Number. Returns ------- out : str Formatted number. z{0:.3g}z+0+z-0-)rzreplacer+ri)nfr&r&r' format_numsztqdm.format_num333333?cCs |dkr |S||d||S)a Exponential moving average: smoothing to give progressively lower weights to older values. Parameters ---------- x : float New value to include in EMA. mu : float, optional Previous EMA value. alpha : float, optional Smoothing factor in range [0, 1], [default: 0.3]. Increase to give more weight to recent values. Ranges from 0 (yields mu) to 1 (yields x). Nrr&)xmualphar&r&r'ema sztqdm.emacs:|tdddfdddgfdd}|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). flushcSsdSr9r&r&r&r&r''z%tqdm.status_printer..cst|dSr9)writer r)fpfp_flushr&r'r1)sz%tqdm.status_printer..fp_writercs6t|}d|dtd|d|d<dS)N rTr)rirZ)rZlen_s)r1last_lenr&r' print_status/s"z)tqdm.status_printer..print_status)getattr)filerr&)rrr1rr'status_printers ztqdm.status_printerFitc Ks.|r||dkrd}|rD|dkrD|r,||9}||9}|r@||9}d}t|} |dkrb|rb||}|rnd|nd}tj}|r|r||qd|nd|d}|r|r||qd|ndd |}|r|dkr|n|}|r||| d }|dk r||| d nd}nt|}|dk rt|nd}z| r2d | nd } Wntk rNYnX|rh|rh|||nd }|r|t|nd}|r|dddk}|r|n|d}nd }d||| ||| }tf||||| |||pd ||r|dkr|n||||||| | ||||d| }|rt||}|d}|d|7}|d kr\|dd|ddS|j|d| r|j|d|s| dd } nd} t }z| jfd|i|}Wn2t k rt | } | jfd|i|}YnX|j s|St ||r td|t|nd|dkrt jn |p(t jd}t|jsLt| rLt | } | jfd|i|}|rpt||S|S| r|d7}|j|d dt }| jfd|i|}|j s|St d |rtd|t|ndt jd}| jfd|i|}|rt||S|S|r|dnd d||| || SdS) a Return a string-based progress bar given some parameters Parameters ---------- n : int or float Number of finished iterations. total : int or float The expected total number of iterations. If meaningless (None), 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 `{bar}` to stay within this bound [default: None]. If `0`, will not print any bar (only stats). The fallback is `{bar:10}`. prefix : str, optional Prefix message (included in total width) [default: '']. Use as {desc} in bar_format string. ascii : bool, optional or str, optional If not set, use unicode (smooth blocks) to fill the meter [default: False]. The fallback is to use ASCII characters " 123456789#". unit : str, optional The iteration unit [default: 'it']. unit_scale : bool or int or float, optional If 1 or True, the number of iterations will be printed with an appropriate SI metric prefix (k = 10^3, M = 10^6, etc.) [default: False]. If any other non-zero number, will scale `total` and `n`. 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='{desc}: {percentage:3.0f}%|' and r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, ' '{rate_fmt}{postfix}]' Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt, percentage, elapsed, elapsed_s, ncols, desc, unit, rate, rate_fmt, rate_noinv, rate_noinv_fmt, rate_inv, rate_inv_fmt, postfix, unit_divisor, remaining, remaining_s. Note that a trailing ": " is automatically removed after {desc} if the latter is empty. postfix : *, optional Similar to `prefix`, but placed at the end (e.g. for additional stats). Note: postfix is usually a string (not a dict) for this method, and will if possible be set to postfix = ', ' + postfix. However other types are supported (#382). unit_divisor : float, optional [default: 1000], ignored unless `unit_scale` is True. Returns ------- out : Formatted meter and stats, ready to display. g?N)TrFrz{0:5.2f}?z/szs/)r}, rUrr)z| {0}/{1} [{2}<{3}, {4}{5}])rn_fmttotal total_fmtelapsedZ elapsed_sncolsdescr~raterate_fmtZ rate_noinvrate_noinv_fmtZrate_inv rate_inv_fmtpostfix unit_divisor remainingZ remaining_sl_barr_bardz {0:3.0f}%|rE)r) percentagez{desc}: z{l_bar}{bar}{r_bar}rmrVT)r_|)rrz{0}{1} [{2}, {3}{4}])rrrrzr+ TypeErrorrcupdaterrUnicodeEncodeErrorr Z format_calledrSrZrrdrerr_rrf) rrrrprefixasciir~ unit_scaler bar_formatrr extra_kwargsZ elapsed_strZinv_raterrrrrrrZ remaining_strZbool_prefix_colon_alreadyrr format_dictr]rZfull_barZnobarresr&r&r' format_meter6sB        ztqdm.format_meterc Ost|}|t|ds&t|_|j||jr|jdksL|j szt ||j|_Wn>t k r}z t dt |tddd|_W5d}~XYnXW5QRX|S)N _instancesz>tqdm:disabling monitor support (monitor_interval = 0) due to: rWrXr)object__new__get_lockrLr raddmonitor_intervalmonitorreportr Exceptionrr+r!)rBargskwargsinstanceer&r&r'rs&    "z tqdm.__new__cs6tfdd|jD}tttt|d|S)zSkips specified instance.c3s*|]"}|k rt|drt|jVqdS)posN)rLryr)r:instrr&r' s z%tqdm._get_free_pos..r)setrr[rqri difference)rBrZ positionsr&rr' _get_free_possztqdm._get_free_posc Cs|jz|j|Wntk r,YnX|jst|jD]8}t|dr:|jt|jkr:|jdd|jd8_q:|js|j rz|j |` Wnt k rYnXd|_ W5QRXdS)zs Remove from list and reposition other bars so that newer bars won't overlap previous bars rTnolockrN) _lockrremovergguirLrryclearrexitAttributeError)rBrrr&r&r'_decr_instancess"    ztqdm._decr_instancesr(c CsD|dk r |ntj}|j||d||||W5QRXdS)z5Print a message via tqdm (without overlap with bars).N)rr)sysstdoutexternal_write_moder)rBrrendrrr&r&r'r;s z tqdm.writeccs|dk r |ntj}|s"|g}t|dgD]F}t|dr2|j|ksbtdd||jfDr2|jdd| |q2dV|D]}|j ddq|s|j dS)z Disable tqdm within context and refresh tqdm when exits. Useful when writing to standard output stream Nrstart_tcss|]}|tjtjfkVqdSr9)rrstderr)r:rr&r&r'rUsz+tqdm.external_write_mode..Tr) rrrrCrrLrallrappendrefreshrrF)rBrrrZ inst_clearedrr&r&r'rDs   ztqdm.external_write_modecCs ||_dS)zSet the global lock.N)r)rBrDr&r&r'set_lock`sz tqdm.set_lockcCst|dst|_|jS)z7Get the global lock. Construct it if it does not exist.r)rLr8rrQr&r&r'res z tqdm.get_lockc s8ddlm}ddlmzddlm}Wntk r@d}YnXzddlmWn>tk rzddl mWntk rdYnXYnXzddl m }m }WnNtk rzddl m }m }Wn$tk rddlm }m }YnXYnXzddl m}Wn"tk r(ddlm}YnXzdd l m}WnBtk r|zdd lm}Wntk rvd}YnXYnXd dgdfd d } | _| |_| d_| d|_| |_| |_| d|_|dk r| |_|dk r| |_| |_| d|_| d|_dk r4| _dS)ab Registers the given `tqdm` class with pandas.core. ( frame.DataFrame | series.Series | groupby.(generic.)DataFrameGroupBy | groupby.(generic.)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 >>> from tqdm.gui import tqdm as 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)PanelN)_Rolling_and_Expanding)DataFrameGroupBy SeriesGroupBy)GroupBy) PanelGroupBy deprecated_tapplycsfdd}|S)Ncs0dt|dd}|dkrdkr,|j}n\t|r@t|}nHdksRt|s|dd}|dkrld}n |dkrxd }|j|j|}ddk rddd<nd|it|dkrtd tjd t j j d z| Wnt k rYnXfd d}t||f|}|S)aT Parameters ---------- df : (DataFrame|Series)[GroupBy] Data (may be grouped). func : function To be applied on the (grouped) data. **kwargs : optional Transmitted to `df.apply()`. rZngroupsNapplymapaxisrindexcolumnsrzExcept func, normal arguments are intentionally not supported by `(DataFrame|Series|GroupBy).progress_apply`. Use keyword arguments instead.rr1cs,jjrjjkrdndd||S)Nrr)r)rrrrrfuncrr&r'wrappers"zDtqdm.pandas..inner_generator..inner..wrapper)poprsize isinstancerigetshaper rrrrZ_is_builtin_funcrclose)Zdfrrrrrrresult)rrr df_functiontargstclasstkwargsrr'inners@        z3tqdm.pandas..inner_generator..innerr&)rrrrrrrr)rr'inner_generatorsDz$tqdm.pandas..inner_generatorrprZ aggregateZ transform)r)Zpandas.core.framerZpandas.core.seriesrpandasrrNZpandas.core.window.rollingrZpandas.core.windowZpandas.core.groupby.genericrrZpandas.core.groupby.groupbyZpandas.core.groupbyrrrZprogress_applyZ progress_mapZprogress_applymapZprogress_aggregateZprogress_transform) rrrrrrrrrrr&rr'rlsb#   I        z tqdm.pandasT皙?$@rc Ksj|dkr|dkotjdk}|dkr(tj}|rDt|t|ddp>dd}| dkrbt|drb|sbd} |dkr|dk rz t|}Wntt fk rd}YnX|t dkrd}| r||_ | |_ |j |||_|j|W5QRX||_||_dS|r^d|_ |j |||_|j|W5QRXd |krNtd t|d tjjd ntd t||dkrz|tjtjfks|r|rt}|r||}nt}|r||}| dkrd} d}nd}|dkrd}|dkrd}| dkrt| } |r| dkst| st|}|dkr(d}||_ |p6d|_||_||_||_||_ ||_!||_"| |_#||_$| |_%| |_ | |_&| |_'||_(||_)||_*||_+||_,d|_-t.|_/||_0d|_1|rz|j2fddi|Wntk r||_1YnX||_3||_|j &|dkr |||_n| |_W5QRX|sT|4|j|_5|j6|j)d|/|_7|j7|_8dS)a6 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 or float, optional The number of expected iterations. If unspecified, len(iterable) is used if possible. If float("inf") or 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 number, e.g. 9e9. leave : bool, optional If [default: True], keeps all traces of the progressbar upon termination of iteration. If `None`, will leave only if `position` is `0`. 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. For encoding, see `write_bytes`. 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 display update interval [default: 0.1] seconds. maxinterval : float, optional Maximum progress display update interval [default: 10] seconds. Automatically adjusts `miniters` to correspond to `mininterval` after long display update lag. Only works if `dynamic_miniters` or monitor thread is enabled. miniters : int or float, optional Minimum progress display update interval, in iterations. If 0 and `dynamic_miniters`, will automatically adjust to equal `mininterval` (more CPU efficient, good for tight loops). If > 0, will skip display of specified number of iterations. Tweak this and `mininterval` to get very efficient loops. If your progress is erratic with both fast and slow iterations (network, skipping items, etc) you should set miniters=1. ascii : bool or str, optional If unspecified or False, use unicode (smooth blocks) to fill the meter. The fallback is to use ASCII characters " 123456789#". disable : bool, optional Whether to disable the entire progressbar wrapper [default: False]. If set to None, disable on non-TTY. unit : str, optional String that will be used to define the unit of each iteration [default: it]. unit_scale : bool or int or float, optional If 1 or True, 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]. If any other non-zero number, will scale `total` and `n`. 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. [default: '{l_bar}{bar}{r_bar}'], where l_bar='{desc}: {percentage:3.0f}%|' and r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, ' '{rate_fmt}{postfix}]' Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt, percentage, elapsed, elapsed_s, ncols, desc, unit, rate, rate_fmt, rate_noinv, rate_noinv_fmt, rate_inv, rate_inv_fmt, postfix, unit_divisor, remaining, remaining_s. Note that a trailing ": " is automatically removed after {desc} if the latter is empty. initial : int or float, optional The initial counter value. Useful when restarting a progress bar [default: 0]. If using float, consider specifying `{n:.3f}` or similar in `bar_format`, or specifying `unit_scale`. 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). postfix : dict or *, optional Specify additional stats to display at the end of the bar. Calls `set_postfix(**postfix)` if possible (dict). unit_divisor : float, optional [default: 1000], ignored unless `unit_scale` is True. write_bytes : bool, optional If (default: None) and `file` is unspecified, bytes will be written in Python 2. If `True` will also write bytes. In all other cases will default to unicode. lock_args : tuple, optional Passed to `refresh` for intermediate output (initialisation, iterating, and updating). gui : bool, optional WARNING: internal parameter - do not use. Use tqdm.gui.tqdm(...) instead. If set, will attempt to use matplotlib animations for a graphical output [default: False]. Returns ------- out : decorated iterator. N)encodingzutf-8)r isattyTinfnestedzQ`nested` is deprecated and automated. Use `position` instead for manual control. rrzUnknown argument(s): rFrUr lock_args)9r version_inforrrrLr rirrfloatiterabledisablerrrrrrrr rrr+rrrrr rleaverr mininterval maxintervalminitersdynamic_minitersrr~rrrr dynamic_ncols smoothingavg_timer_timerr set_postfix last_print_nrspr last_print_tr)r/rrrrrrrrrrrr~rrrrinitialpositionrr write_bytesrrrZ_dynamic_ncolsrr&r&r'r.st                 z tqdm.__init__cCs0|jdk r|jdkS|jdkr&tdt|jS)Nrz/bool() undefined when iterable == total == None)rrrboolrGr&r&r'__bool__ s    z tqdm.__bool__cCs|Sr9)r&rGr&r&r' __nonzero__sztqdm.__nonzero__cCsJ|jdkr|jSt|jdr(|jjdSt|jdr>t|jSt|ddS)Nrr__len__r)rrrLrrirrGr&r&r'r(s  z tqdm.__len__cCs|Sr9r&rGr&r&r'rHsztqdm.__enter__cCsDz |Wn2tk r>|||fdkr,tdtddYnXdS)N)NNNzAttributeError ignoredrWrX)rrrr)r/exc_type exc_value tracebackr&r&r'rJs  z tqdm.__exit__cCs |dSr9)rrGr&r&r'__del__(sz tqdm.__del__cCs|jf|jSr9)rrrGr&r&r'__repr__+sz tqdm.__repr__cCstt|ddS)Nrl)ryrrGr&r&r' _comparable.sztqdm._comparablecCst|Sr9)idrGr&r&r'__hash__2sz tqdm.__hash__ccs|j}|jr |D] }|VqdS|j}|j}|j}|j}|j}|j}|j} |j } |j } |j } t |dst dt|jdtjjd|D]}|V| d7} | ||jkr|j}| |} | |kr| }| |}| r| r|r| |}||| | } | |_ | |_|j|jd|r||r@| |kr@|r2||| }n ||| }n<| rr|}|rb| rb||| 9}|||| }n t||}| |_|_}||_}||_q||_| |_||_|dS)z6Backward-compatibility to use: for x in tqdm(iterable)Nr APlease use `tqdm.gui.tqdm(...)` instead of `tqdm(..., gui=True)` rrrr)rrrrrrr!rrrrrrLr rrrrrrrrrZr)r/robjrrrrr!rrrrrdelta_tcur_tdelta_itrr&r&r'__iter__5sj        z tqdm.__iter__rcCsv|jr dS|dkr |j|7_|j|7_|j|j|jkrr||j}||jkrr|}|j|j}|jr|r|r||}|||j |j|_ t |dst dt |j dtjjd|j|jd|jrd|jr||jkr|jr||j||_n||j||_nP|jrV|j||jr<|r<|j|ndd|j|j|_nt|j||_|j|_||_dS) a 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 or float, optional Increment to add to the internal counter of iterations [default: 1]. If using float, consider specifying `{n:.3f}` or similar in `bar_format`, or specifying `unit_scale`. Nrr r1rrrr)rrrrrr!rrrrrLr rrrrrrrrrrZ)r/rr3r4r5rr&r&r'rsZ   z tqdm.updatec sjr dSd_tj}tds2dSfdd}z |dWn:tk r}zdt|krrWY dSW5d}~XYnXjdkr|dknj}j@|rd_ j dd |d nj d|d |s|d W5QRXdS) z3Cleanup and (if leave=False) close the progressbar.NTr csjt|dSr9)rrr rrGr&r'r1sztqdm.close..fp_writerUclosedr)rr()r0rr) rryrrrL ValueErrorr+rrrdisplay)r/rr1rrr&rGr'rs.         z tqdm.closecCsb|jr dS|s|j|t|j|d|jd|t|j |s^|j dS)zClear current bar display.NrUr) rrrCmovetoryrr rrrF)r/rr&r&r'rs   z tqdm.clearcCsH|jr dS|s.|r$|jj|s.dSn |j||sD|jdS)a Force refresh the display of this bar. Parameters ---------- nolock : bool, optional If `True`, does not lock. If [default: `False`]: calls `acquire()` on internal lock. lock_args : tuple, optional Passed to internal lock's `acquire()`. If specified, will only `display()` if `acquire()` returns `True`. NFT)rrrCr9rF)r/rrr&r&r'r s    z tqdm.refreshcCs&|}|j||j7_||_dS)z(Restart tqdm timer from last print time.N)rrr!)r/r4r&r&r'unpause'sz tqdm.unpausecCs6d|_|_||_|_|dk r*||_|dS)z Resets to 0 iterations for repeated use. Consider combining with `leave=True`. Parameters ---------- total : int or float, optional. Total to use for the new bar. rN)rrrr!rrr)r/rr&r&r'reset-s z tqdm.resetcCs"|r |dnd|_|r|dS)z Set/modify description of the progress bar. Parameters ---------- desc : str, optional refresh : bool, optional Forces refresh [default: True]. r)rUNrrr/rrr&r&r'set_description=s ztqdm.set_descriptioncCs|pd|_|r|dS)z-Set/modify description without ': ' appended.rUNr=r>r&r&r'set_description_strKs ztqdm.set_description_strc st|dkrgn|t|D]}|||<q D]D}t|tr`|||<q:t|ts:t||<q:dfddD|_ |r| dS)a8 Set/modify postfix (additional stats) with automatic formatting based on datatype. Parameters ---------- ordered_dict : dict or OrderedDict, optional refresh : bool, optional Forces refresh [default: True]. kwargs : dict, optional Nrc3s"|]}|d|VqdS)=N)strip)r:keyrr&r'rksz#tqdm.set_postfix..) r sortedkeysrrrr r+rorr)r/Z ordered_dictrrrCr&rDr'rQs   ztqdm.set_postfixcCst||_|r|dS)zS Postfix without dictionary expansion, similar to prefix handling. N)r+rr)r/rrr&r&r'set_postfix_strps ztqdm.set_postfix_strcCs.|jtd|t| |jdS)Nr()rrr r r)r/rr&r&r'r:xs z tqdm.movetocCsnt|j|jt|dr"||jnd|jr6||jn|j|j |j |j |j |j rZd|j nd|j|j|jd S)z'Public API for read-only member access.rrrN) rrrrrrr~rrrrr)rcrrrLrrrrrrrr~rrrrrrGr&r&r'r}s$ztqdm.format_dictcCsN|dkrt|j}|r ||||dkr4|n||rJ|| dS)a Use `self.sp` to display `msg` in the specified `pos`. Consider overloading this function when inheriting to use e.g.: `self.some_frontend(**self.format_dict)` instead of `self.sp`. Parameters ---------- msg : str, optional. What to display (default: `repr(self)`). pos : int, optional. Position to `moveto` (default: `abs(self.pos)`). N)ryrr:r r-)r/r0rr&r&r'r9s   z tqdm.displayc ksH|fd|i|,}|r*d|_d|_d|_t|j||VW5QRXdS)a stream : file-like object. method : str, "read" or "write". The result of `read()` and the first argument of `write()` should have a `len()`. >>> with tqdm.wrapattr(file_obj, "read", total=file_obj.size) as fobj: ... while True: ... chunk = fobj.read(chunk_size) ... if not chunk: ... break rBTiN)r~rrrr)rstreammethodrbytesrrr&r&r'wrapattrs z tqdm.wrapattr)rUrr)Nr) NrUFrFNNNrr)N)Nr(F)NF)NNNTNNrr NNFrFFrNrNNrrNNF)r)F)FN)N)NT)NT)NT)rUT)NN)NT)1r#r$r%r5rr staticmethodrrrrrrrrRrrrrrrrrr.r&r'r(rHrJr,r-propertyr.r0r6rrrrr;r<r?r@rrGr:rr9rLr&r&r&r'rs      I      ' z  U L(         cOstt|f|S)zh A shortcut for tqdm(xrange(*args), **kwargs). On Python3+ range is used instead of xrange. )rrrr&r&r'rs)5r5 __future__rrutilsrrrrr r r r r rrrrrrr_monitorr contextlibrrZnumbersrr threadingrPwarningsr __author____all__rrrgrWarningr FutureWarningrDeprecationWarningr RuntimeWarningr!rr8r=rSrrr&r&r&r'sT H       7;