# Buggy code
def __init__(
    self,
    iterable=None,
    desc=None,
    total=None,
    leave=True,
    file=sys.stderr,
    ncols=None,
    mininterval=0.1,
    maxinterval=10.0,
    miniters=None,
    ascii=None,
    disable=False,
    unit="it",
    unit_scale=False,
    dynamic_ncols=False,
    smoothing=0.3,
    bar_format=None,
    initial=0,
    position=None,
    gui=False,
    **kwargs,
):
    """
    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.
    """
    if disable:
        self.iterable = iterable
        self.disable = disable
        self.pos = self._get_free_pos(self)
        self._instances.remove(self)
        return

    if kwargs:
        self.disable = True
        self.pos = self._get_free_pos(self)
        self._instances.remove(self)
        raise (
            TqdmDeprecationWarning(
                """\
`nested` is deprecated and automated. Use position instead for manual control.
""",
                fp_write=getattr(file, "write", sys.stderr.write),
            )
            if "nested" in kwargs
            else TqdmKeyError("Unknown argument(s): " + str(kwargs))
        )

    # Preprocess the arguments
    if total is None and iterable is not None:
        try:
            total = len(iterable)
        except (TypeError, AttributeError):
            total = None

    if (
        (ncols is None) and (file in (sys.stderr, sys.stdout))
    ) or dynamic_ncols:  # pragma: no cover
        if dynamic_ncols:
            dynamic_ncols = _environ_cols_wrapper()
            ncols = dynamic_ncols(file)
        else:
            ncols = _environ_cols_wrapper()(file)

    if miniters is None:
        miniters = 0
        dynamic_miniters = True
    else:
        dynamic_miniters = False

    if mininterval is None:
        mininterval = 0

    if maxinterval is None:
        maxinterval = 0

    if ascii is None:
        ascii = not _supports_unicode(file)

    if bar_format and not ascii:
        # Convert bar format into unicode since terminal uses unicode
        bar_format = _unicode(bar_format)

    if smoothing is None:
        smoothing = 0

    # Store the arguments
    self.iterable = iterable
    self.desc = desc + ": " if desc else ""
    self.total = total
    self.leave = leave
    self.fp = file
    self.ncols = ncols
    self.mininterval = mininterval
    self.maxinterval = maxinterval
    self.miniters = miniters
    self.dynamic_miniters = dynamic_miniters
    self.ascii = ascii
    self.disable = disable
    self.unit = unit
    self.unit_scale = unit_scale
    self.gui = gui
    self.dynamic_ncols = dynamic_ncols
    self.smoothing = smoothing
    self.avg_time = None
    self._time = time
    self.bar_format = bar_format

    # Init the iterations counters
    self.last_print_n = initial
    self.n = initial

    # if nested, at initial sp() call we replace '\r' by '\n' to
    # not overwrite the outer progress bar
    self.pos = self._get_free_pos(self) if position is None else position

    if not gui:
        # Initialize the screen printer
        self.sp = self.status_printer(self.fp)
        if self.pos:
            self.moveto(self.pos)
        self.sp(
            self.format_meter(
                self.n,
                total,
                0,
                (dynamic_ncols(file) if dynamic_ncols else ncols),
                self.desc,
                ascii,
                unit,
                unit_scale,
                None,
                bar_format,
            )
        )
        if self.pos:
            self.moveto(-self.pos)

    # Init the time counter
    self.start_t = self.last_print_t = self._time()


# Traceback (ZeroDivisionError)
Traceback (most recent call last):
File "x.py", line 273, in train
bar.update(0)
File "C:\Python27\lib\site-packages\tqdm\_tqdm.py", line 808, in update
if self.avg_time is None \
ZeroDivisionError: float division by zero

# Fixed code
def __init__(
    self,
    iterable=None,
    desc=None,
    total=None,
    leave=True,
    file=sys.stderr,
    ncols=None,
    mininterval=0.1,
    maxinterval=10.0,
    miniters=None,
    ascii=None,
    disable=False,
    unit="it",
    unit_scale=False,
    dynamic_ncols=False,
    smoothing=0.3,
    bar_format=None,
    initial=0,
    position=None,
    gui=False,
    **kwargs,
):
    """
    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.
    """
    if disable:
        self.iterable = iterable
        self.disable = disable
        self.pos = self._get_free_pos(self)
        self._instances.remove(self)
        return

    if kwargs:
        self.disable = True
        self.pos = self._get_free_pos(self)
        self._instances.remove(self)
        raise (
            TqdmDeprecationWarning(
                """\
`nested` is deprecated and automated. Use position instead for manual control.
""",
                fp_write=getattr(file, "write", sys.stderr.write),
            )
            if "nested" in kwargs
            else TqdmKeyError("Unknown argument(s): " + str(kwargs))
        )

    # Preprocess the arguments
    if total is None and iterable is not None:
        try:
            total = len(iterable)
        except (TypeError, AttributeError):
            total = None

    if (
        (ncols is None) and (file in (sys.stderr, sys.stdout))
    ) or dynamic_ncols:  # pragma: no cover
        if dynamic_ncols:
            dynamic_ncols = _environ_cols_wrapper()
            ncols = dynamic_ncols(file)
        else:
            ncols = _environ_cols_wrapper()(file)

    if miniters is None:
        miniters = 0
        dynamic_miniters = True
    else:
        dynamic_miniters = False

    if mininterval is None:
        mininterval = 0

    if maxinterval is None:
        maxinterval = 0

    if ascii is None:
        ascii = not _supports_unicode(file)

    if bar_format and not ascii:
        # Convert bar format into unicode since terminal uses unicode
        bar_format = _unicode(bar_format)

    if smoothing is None:
        smoothing = 0

    # Store the arguments
    self.iterable = iterable
    self.desc = desc + ": " if desc else ""
    self.total = total
    self.leave = leave
    self.fp = file
    self.ncols = ncols
    self.mininterval = mininterval
    self.maxinterval = maxinterval
    self.miniters = miniters
    self.dynamic_miniters = dynamic_miniters
    self.ascii = ascii
    self.disable = disable
    self.unit = unit
    self.unit_scale = unit_scale
    self.gui = gui
    self.dynamic_ncols = dynamic_ncols
    self.smoothing = smoothing
    self.avg_time = None
    self._time = time
    self.bar_format = bar_format

    # Init the iterations counters
    self.last_print_n = initial
    self.n = initial

    # if nested, at initial sp() call we replace '\r' by '\n' to
    # not overwrite the outer progress bar
    self.pos = self._get_free_pos(self) if position is None else position

    if not gui:
        # Initialize the screen printer
        self.sp = self.status_printer(self.fp)
        if self.pos:
            self.moveto(self.pos)
        self.sp(
            self.format_meter(
                self.n,
                total,
                0,
                (dynamic_ncols(file) if dynamic_ncols else ncols),
                self.desc,
                ascii,
                unit,
                unit_scale,
                None,
                bar_format,
            )
        )
        if self.pos:
            self.moveto(-self.pos)

    # Init the time counter
    self.start_t = self.last_print_t = self._time()

    # Avoid race conditions by setting a flag at the very end of init
    self.started = True