B e]@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 _text_width ComparableRE_ANSI _is_ascii FormatReplaceSimpleTextIOWrapperCallbackIOWrapper)TMonitor)contextmanagerN)Number)time)warnz github.com/ZnoamraphZobiwanusZkmikeZhadimZ casperdclZlrq3000tqdmtrange TqdmTypeError TqdmKeyError TqdmWarningTqdmExperimentalWarningTqdmDeprecationWarningTqdmMonitorWarningc@s eZdZdS)rN)__name__ __module__ __qualname__r%r%*/tmp/pip-install-b8evvk6i/tqdm/tqdm/std.pyr"sc@s eZdZdS)rN)r"r#r$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 z: ) __class__r"strrstripsuperr__init__)selfmsgfp_writeak)r(r%r&r,/s$zTqdmWarning.__init__)N)r"r#r$__doc__r, __classcell__r%r%)r(r&r*sc@seZdZdZdS)rz(beta feature, unstable API and behaviourN)r"r#r$r2r%r%r%r&r7sc@s eZdZdS)r N)r"r#r$r%r%r%r&r <sc@seZdZdZdS)r!z>tqdm monitor errors which do not affect external functionalityN)r"r#r$r2r%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|jgD|_dS)NcSsg|]}|dk r|qS)Nr%).0Zlkr%r%r& Usz1TqdmDefaultWriteLock.__init__..)create_mp_lockcreate_th_locktypemp_lockth_locklocks)r-clsr%r%r&r,OszTqdmDefaultWriteLock.__init__cOs x|jD]}|j||qWdS)N)r<acquire)r-r0r1lockr%r%r&r>Ws zTqdmDefaultWriteLock.acquirecCs&x |jdddD] }|qWdS)N)r<release)r-r?r%r%r&rA[szTqdmDefaultWriteLock.releasecCs |dS)N)r>)r-r%r%r& __enter___szTqdmDefaultWriteLock.__enter__cGs |dS)N)rA)r-excr%r%r&__exit__bszTqdmDefaultWriteLock.__exit__cCsZt|dsVyddlm}||_Wn2tk r<d|_Yntk rTd|_YnXdS)Nr:r)RLock)hasattrmultiprocessingrEr: ImportErrorOSError)r=rEr%r%r&r7es    z#TqdmDefaultWriteLock.create_mp_lockcCs8t|ds4yt|_Wntk r2d|_YnXdS)Nr;)rFthrEr;rI)r=r%r%r&r8ps  z#TqdmDefaultWriteLock.create_th_lockN) r"r#r$r2r,r>rArBrD classmethodr7r8r%r%r%r&r4Fs r4c @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%r@z cCsVd|krdks4ntdtddtdtd|}|dks@t||_||_||_dS)Nrrzclamping frac to range [0, 1]) stacklevel)rrmaxminAssertionErrorfrac default_lencharset)r-rUrVrWr%r%r&r,s z Bar.__init__c Cs|r||d}yt|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)Nr@)r0ubrr) lowerdictASCIIUTFBLANKKeyErrorrWintrVlendivmodrU) r- format_spec_typerWZN_BARSZnsymsZ bar_lengthZfrac_bar_lengthbarZfrac_barr%r%r& __format__s.      zBar.__format__N) r"r#r$r2r\joinmaprranger]r^r,rfr%r%r%r&rLs   rLc@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. rONrNcCs~xndD]f}t|dkrdt|dkrRt|dkr@d|||Sd|||Sd|||S||}qWd||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. )rNr1MGTPEZg<@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)rbr`rr)tminsshmr%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-)rrreplacer)ra)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). flushcSsdS)Nr%r%r%r%r&'z%tqdm.status_printer..cst|dS)N)writer )r{)fpfp_flushr%r&r/)sz%tqdm.status_printer..fp_writercs6t|}d|dtd|d|d<dS)N rMr)rarR)r{Zlen_s)r/last_lenr%r& print_status/s"z)tqdm.status_printer..print_status)getattr)filerr%)rrr/rr&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}y| r2d | nd } Wntk rNYnX|rh|rh|||nd }|r|t|nd}|r|dddk}|r|n|d}nd }d||| ||| }tf||||| |||pd ||r|dkr|n||||||| | ||||d| }|rh||}|d}|d|7}|d kr\|dd|ddS|j|d| r|j|d|s| dd } nd} t }y| jfd|i|}Wn2t k rt | } | jfd|i|}YnX|j s|St ||rtd|ttd |nd|dkr&t jn |p0t jd}t|jsTt| rTt | } | jfd|i|S| r|d7}|j|d dt }| jfd|i|}|j s|St d |rtd|ttd |ndt jd}| jfd|i|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/)ruz, rNrz: z| {0}/{1} [{2}<{3}, {4}{5}])rn_fmttotal total_fmtelapsedZ elapsed_sncolsdescrvraterate_fmtZ rate_noinvrate_noinv_fmtZrate_inv rate_inv_fmtpostfix unit_divisor remainingZ remaining_sl_barr_bardz {0:3.0f}%|r@)r) percentagez{desc}: z{l_bar}{bar}{r_bar}rerOT)rW|)rrz{0}{1} [{2}, {3}{4}])rr~rwrrr) TypeErrorr[updaterrUnicodeEncodeErrorr Z format_calledrLrRrrsubr\r]rrWr^)rrrrprefixasciirv unit_scaler bar_formatrr extra_kwargsZ elapsed_strZinv_raterwrrrrrrZ remaining_strZbool_prefix_colon_alreadyrr format_dictrUrZfull_barZnobarr%r%r& format_meter6sB   &&     " " ztqdm.format_meterc Ost|}|t|ds&t|_|j||jr|jdksL|j syt ||j|_Wn>t k r}z t dt |tddd|_Wdd}~XYnXWdQRX|S)N _instancesz>tqdm:disabling monitor support (monitor_interval = 0) due to: rP)rQr)object__new__get_lockrFr raddmonitor_intervalmonitorreportr Exceptionrr)r!)r=argskwargsinstanceer%r%r&rs      "z tqdm.__new__cs6tfdd|jD}tttt|d|S)zSkips specified instance.c3s*|]"}|k rt|drt|jVqdS)posN)rFrqr)r5inst)rr%r& sz%tqdm._get_free_pos..r)setrrSrira difference)r=rZ positionsr%)rr& _get_free_possztqdm._get_free_posc Cs|jy|j|Wntk r,YnX|jsxxB|jD]8}t|dr<|jt|jkr<|jdd|jd8_q.T)r) rrrr>rrFrallrappendrefreshrrA)r=rrrZ inst_clearedrr%r%r&rBs   ztqdm.external_write_modecCs ||_dS)zSet the global lock.N)r)r=r?r%r%r&set_lock^sz tqdm.set_lockcCst|dst|_|jS)z7Get the global lock. Construct it if it does not exist.r)rFr4r)r=r%r%r&rcs z tqdm.get_lockc sddlm}ddlmyddlm}Wntk r@d}YnXyddlmWntk rjdYnXyddl m }m }WnNtk ryddl m }m }Wn$tk rddl m }m }YnXYnXyddl m}Wn"tk rddl m}YnXydd l m}WnBtk rVydd l m}Wntk rPd}YnXYnXd dgdfd d } | _| |_| d_| d|_| |_| |_| d|_|dk r| |_|dk r| |_| |_| d|_| d|_dk r| _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 y| 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.r)r/cs,jjrjjkrdndd||S)Nrr)r)rrr)rr)funcryr%r&wrappers"zDtqdm.pandas..inner_generator..inner..wrapper)poprsize isinstanceragetshaper rrrrZ_is_builtin_funcrclose)Zdfrrrrrrresult)rrr df_functiontargstclasstkwargs)rryr&inners<         z3tqdm.pandas..inner_generator..innerr%)rr)rrrrrr)rr&inner_generatorsDz$tqdm.pandas..inner_generatorrhrZ aggregateZ transform)r)Zpandas.core.framerZpandas.core.seriesrpandasrrHZpandas.core.windowrZpandas.core.groupby.genericrrZpandas.core.groupby.groupbyZpandas.core.groupbyrrrZprogress_applyZ progress_mapZprogress_applymapZprogress_aggregateZprogress_transform) rrrrrrrrrrr%)rrrrrrr&rjs\#    I        z tqdm.pandasT皙?$@rc Ksj|dkr|dkotjdk}|dkr(tj}|rDt|t|ddp>dd}| dkrbt|drb|sbd} |dkr|dk ry t|}Wntt fk rd}YnX|t dkrd}| r||_ | |_ |j |||_|j|WdQRX||_||_dS|r^d|_ |j |||_|j|WdQRXd |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|ry|j2fddi|Wntk r||_1YnX||_3||_|j &|dkr |||_n| |_WdQRX|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)risattyTinfnestedzQ`nested` is deprecated and automated. Use `position` instead for manual control. r)r/zUnknown argument(s): rFrNr) lock_args)9r version_inforrrrFrrarrfloatiterabledisablerrrrrrrr rrr)rrrrr rleaverr mininterval maxintervalminitersdynamic_minitersrrvrrrr dynamic_ncols smoothingavg_timer_timerr set_postfix last_print_nrspr last_print_tr)r-rrrrrrrrrrrrvrr r rinitialpositionrr write_bytesrrrZ_dynamic_ncolsr r%r%r&r,st     "           z tqdm.__init__cCs0|jdk r|jdkS|jdkr&tdt|jS)Nrz/bool() undefined when iterable == total == None)rrrbool)r-r%r%r&__bool__s    z tqdm.__bool__cCs|S)N)r)r-r%r%r& __nonzero__sztqdm.__nonzero__cCsJ|jdkr|jSt|jdr(|jjdSt|jdr>t|jSt|ddS)Nrr__len__r)rrrFrrar)r-r%r%r&rsz tqdm.__len__cCs|S)Nr%)r-r%r%r&rBsztqdm.__enter__cCsDy |Wn2tk r>|||fdkr,tdtddYnXdS)N)NNNzAttributeError ignoredrP)rQ)rrrr)r-exc_type exc_value tracebackr%r%r&rDs  z tqdm.__exit__cCs |dS)N)r)r-r%r%r&__del__#sz tqdm.__del__cCs|jf|jS)N)rr)r-r%r%r&__repr__&sz tqdm.__repr__cCstt|ddS)Nrl)rqr)r-r%r%r& _comparable)sztqdm._comparablecCst|S)N)id)r-r%r%r&__hash__-sz tqdm.__hash__ccs|j}|jr$x|D] }|VqWdS|j}|j}|j}|j}|j}|j}|j} |j } |j } |j } t |dst dt|jdtjjdx&|D]}|V| d7} | ||jkr|j}| |} | |kr| }| |}| r| r|r| |}||| | } | |_ | |_|j|jd|r|rN| |krN|r@||| }n ||| }n<| r|}|rp| rp||| 9}|||| }n t||}| |_|_}||_}||_qW||_| |_||_|dS)z6Backward-compatibility to use: for x in tqdm(iterable)NrzAPlease use `tqdm.gui.tqdm(...)` instead of `tqdm(..., gui=True)` r)r/r)r)rrrrrr rrrr r r rFr rrrrrrrrrRr)r-robjrrrr rrrr r rdelta_tcur_tdelta_itrr%r%r&__iter__0sh         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`. NrrzAPlease use `tqdm.gui.tqdm(...)` instead of `tqdm(..., gui=True)` r)r/)rr)rrrrr rrr rr rFr rrrrrrrr rrR)r-rr"r#r$rr%r%r&rs@   z tqdm.updatec sjr dSd_tj}tds2dSfdd}y |dWn4tk r~}zdt|krldSWdd}~XYnXjdkr|dknj}j@|rd_ j dd |d nj d|d |s|d WdQRXdS) z3Cleanup and (if leave=False) close the progressbar.NTrcsjt|dS)N)rrr )r{)r-r%r&r/sztqdm.close..fp_writerNclosedr)rr')r.rr) rrqrrrF ValueErrorr)rrr display)r-rr/rrr%)r-r&rs.        z tqdm.closecCsb|jr dS|s|j|t|j|d|jd|t|j |s^|j dS)zClear current bar display.NrNr) rrr>movetorqrrrrrA)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)rrr>r(rA)r-rrr%r%r&rs    z tqdm.refreshcCs&|}|j||j7_||_dS)z(Restart tqdm timer from last print time.N)r rr)r-r#r%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)rrr rrrr)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]. z: rNN)rr)r-rrr%r%r&set_description8s ztqdm.set_descriptioncCs|pd|_|r|dS)z-Set/modify description without ': ' appended.rNN)rr)r-rrr%r%r&set_description_strFs ztqdm.set_description_strc st|dkrgn|x t|D]}|||<q"WxPD]D}t|trf|||<q@t|ts@t||<q@WdfddD|_ |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 Nz, c3s"|]}|d|VqdS)=N)strip)r5key)rr%r&rfsz#tqdm.set_postfix..) r sortedkeysrrrr r)rgrr)r-Z ordered_dictrrr0r%)rr&rLs ztqdm.set_postfixcCst||_|r|dS)zS Postfix without dictionary expansion, similar to prefix handling. N)r)rr)r-r{rr%r%r&set_postfix_strks ztqdm.set_postfix_strcCs.|jtd|t| |jdS)Nr')rrr r r)r-rr%r%r&r)ss 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) rrrrrrrvrrrrr)r[rrrFr rr rrrrrvrr rrr)r-r%r%r&rxs 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)rqrr)rr)r-r.rr%r%r&r(s   z tqdm.displayc ksH|fd|i|,}|r*d|_d|_d|_t|j||VWdQRXdS)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)rvrrrr)rstreammethodrbytesrryr%r%r&wrapattrs z tqdm.wrapattr)rNrj)Nr) NrNFrFNNNrj)N)Nr'F)NF)NNNTNNrrNNFrFFrNrNNrjNNF)r)F)FN)N)NT)NT)NT)rNT)NN)NT)1r"r#r$r2rr staticmethodrwr~rrrrrrKrrrrrrrrr,rrrrBrDrrpropertyrr r%rrrrr*r+r,r-rr3r)rr(r8r%r%r%r&rs|      E      % t  U L(         cOstt|f|S)zh A shortcut for tqdm(xrange(*args), **kwargs). On Python3+ range is used instead of xrange. )rr)rrr%r%r&rs)5r2 __future__rrutilsrrrrr r r r r rrrrrrr_monitorr contextlibrrnumbersrr threadingrJwarningsr __author____all__rrr_rWarningr FutureWarningrDeprecationWarningr RuntimeWarningr!rr4r8rLrrr%r%r%r& sHH        7;