# Buggy code
def display(
    self,
    msg=None,
    pos=None,
    # additional signals
    close=False,
    bar_style=None,
):
    # Note: contrary to native tqdm, msg='' does NOT clear bar
    # goal is to keep all infos if error happens so user knows
    # at which iteration the loop failed.

    # Clear previous output (really necessary?)
    # clear_output(wait=1)

    # Update description
    if self.desc:
        pbar.description = self.desc
        self.desc = None  # trick to place description before the bar
        if IPYW >= 7:
            pbar.style.description_width = "initial"

    if not msg and not close:
        msg = self.__repr__()

    pbar, ptext = self.container.children

    # Get current iteration value from format_meter string
    if self.total:
        # n = None
        if msg:
            npos = msg.find(r"/|/")  # cause we use bar_format=r'{n}|...'
            # Check that n can be found in msg (else n > total)
            if npos >= 0:
                n = float(msg[:npos])  # get n from string
                msg = msg[npos + 3 :]  # remove from string

                # Update bar with current n value
                if n is not None:
                    pbar.value = n

    # Print stats
    if msg:  # never clear the bar (signal: msg='')
        msg = msg.replace("||", "")  # remove inesthetical pipes
        msg = escape(msg)  # html escape special characters (like '?')
        ptext.value = msg

    # Change bar style
    if bar_style:
        # Hack-ish way to avoid the danger bar_style being overridden by
        # success because the bar gets closed after the error...
        if not (pbar.bar_style == "danger" and bar_style == "success"):
            pbar.bar_style = bar_style

    # Special signal to close the bar
    if close and pbar.bar_style != "danger":  # hide only if no error
        try:
            self.container.close()
        except AttributeError:
            self.container.visible = False


# Traceback (TypeError)
for _ in tqdm_notebook(range(10), ncols='400px', bar_format='{bar}'):
sleep(0.1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-aced8917afa9> in <module>()
1 # px ncols
----> 2 for _ in tqdm_notebook(range(10),ncols='400px', bar_format='{bar}'): #400px
3     sleep(0.1)

/usr/local/anaconda/lib/python3.6/site-packages/tqdm/__init__.py in tqdm_notebook(*args, **kwargs)
23     """See tqdm._tqdm_notebook.tqdm_notebook for full documentation"""
24     from ._tqdm_notebook import tqdm_notebook as _tqdm_notebook
---> 25     return _tqdm_notebook(*args, **kwargs)
26
27

/usr/local/anaconda/lib/python3.6/site-packages/tqdm/_tqdm_notebook.py in __init__(self, *args, **kwargs)
203         # Print initial bar state
204         if not self.disable:
--> 205             self.sp(self.__repr__())  # same as self.refresh without clearing
206
207     def __iter__(self, *args, **kwargs):

/usr/local/anaconda/lib/python3.6/site-packages/tqdm/_tqdm.py in __repr__(self, elapsed)
890             self.desc, self.ascii, self.unit,
891             self.unit_scale, 1 / self.avg_time if self.avg_time else None,
--> 892             self.bar_format, self.postfix, self.unit_divisor)
893
894     @property

/usr/local/anaconda/lib/python3.6/site-packages/tqdm/_tqdm.py in format_meter(n, total, elapsed, ncols, prefix, ascii, unit, unit_scale, rate, bar_format, postfix, unit_divisor)
363             # Formatting progress bar
364             # space available for bar's display
--> 365             N_BARS = max(1, ncols - len(l_bar) - len(r_bar)) if ncols \
366                 else 10
367

TypeError: unsupported operand type(s) for -: 'str' and 'int'

# Fixed code
def display(
    self,
    msg=None,
    pos=None,
    # additional signals
    close=False,
    bar_style=None,
):
    # Note: contrary to native tqdm, msg='' does NOT clear bar
    # goal is to keep all infos if error happens so user knows
    # at which iteration the loop failed.

    # Clear previous output (really necessary?)
    # clear_output(wait=1)

    if not msg and not close:
        msg = self.__repr__()

    pbar, ptext = self.container.children
    pbar.value = self.n

    if msg:
        # html escape special characters (like '&')
        if "<bar/>" in msg:
            left, right = map(escape, msg.split("<bar/>", 1))
        else:
            left, right = "", escape(msg)

        # remove inesthetical pipes
        if left and left[-1] == "|":
            left = left[:-1]
        if right and right[0] == "|":
            right = right[1:]

        # Update description
        pbar.description = left
        if IPYW >= 7:
            pbar.style.description_width = "initial"

        # never clear the bar (signal: msg='')
        if right:
            ptext.value = right

    # Change bar style
    if bar_style:
        # Hack-ish way to avoid the danger bar_style being overridden by
        # success because the bar gets closed after the error...
        if not (pbar.bar_style == "danger" and bar_style == "success"):
            pbar.bar_style = bar_style

    # Special signal to close the bar
    if close and pbar.bar_style != "danger":  # hide only if no error
        try:
            self.container.close()
        except AttributeError:
            self.container.visible = False