tqdm/tests_notebook.ipynb

339 lines
6.8 KiB
Plaintext
Raw Normal View History

2021-03-08 22:26:04 +00:00
{
"cells": [
2021-03-08 23:53:50 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This file is part of the [test suite](./tests) and will be moved there when [nbval#116](https://github.com/computationalmodelling/nbval/issues/116#issuecomment-793148404) is fixed.\n",
"\n",
"See [DEMO.ipynb](DEMO.ipynb) instead for notebook examples."
]
},
2021-03-08 22:26:04 +00:00
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
2021-03-08 23:53:50 +00:00
"from functools import partial\n",
"\n",
"from tqdm.notebook import tqdm_notebook\n",
"from tqdm.notebook import tnrange\n",
"\n",
"# avoid displaying widgets by default (pollutes output cells)\n",
"tqdm = partial(tqdm_notebook, display=False)\n",
"trange = partial(tnrange, display=False)"
2021-03-08 22:26:04 +00:00
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on function display in module tqdm.notebook:\n",
"\n",
"display(self, msg=None, pos=None, close=False, bar_style=None)\n",
" Use `self.sp` to display `msg` in the specified `pos`.\n",
" \n",
" Consider overloading this function when inheriting to use e.g.:\n",
" `self.some_frontend(**self.format_dict)` instead of `self.sp`.\n",
" \n",
" Parameters\n",
" ----------\n",
" msg : str, optional. What to display (default: `repr(self)`).\n",
" pos : int, optional. Position to `moveto`\n",
" (default: `abs(self.pos)`).\n",
"\n"
]
}
],
"source": [
2021-03-08 23:53:50 +00:00
"help(tqdm_notebook.display)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# basic use"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7c18c038bf964b55941e228503292506",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/10 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"9\n"
]
2021-03-09 00:53:19 +00:00
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e29668be41ca4e40b16fb98572b333a5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/10 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
2021-03-08 23:53:50 +00:00
}
],
"source": [
2021-03-09 00:53:19 +00:00
"with tqdm_notebook(range(10)) as t:\n",
" for i in t:\n",
" print(i)\n",
"\n",
"t = tqdm_notebook(total=10)\n",
"t.update()\n",
"t.refresh()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# reset"
2021-03-08 23:53:50 +00:00
]
},
{
"cell_type": "code",
2021-03-09 00:53:19 +00:00
"execution_count": 4,
2021-03-08 23:53:50 +00:00
"metadata": {},
2021-03-09 00:53:19 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 10%|█ | 1/10 [00:00<00:00, 30.04it/s]\n",
" 20%|██ | 1/5 [00:00<00:00, 495.37it/s]\n"
]
}
],
"source": [
"print(t)\n",
"t.reset(total=5)\n",
"t.update(1)\n",
"print(t)"
]
2021-03-08 23:53:50 +00:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# repr"
]
},
{
"cell_type": "code",
2021-03-09 00:53:19 +00:00
"execution_count": 5,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0%| | 0/9 [00:00<?, ?it/s]\n",
" 0%| | 0/9 [00:00<?, ?it/s]\n",
"1\n",
" 0%| | 0/9 [00:00<?, ?it/s]\n",
" 0%| | 0/9 [00:00<?, ?it/s]\n"
]
}
],
"source": [
"with trange(1, 10) as pbar:\n",
" print(pbar)\n",
" print(pbar.container)\n",
" it = iter(pbar)\n",
" print(next(it))\n",
" print(pbar)\n",
" print(pbar.container)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# display"
]
},
{
"cell_type": "code",
2021-03-09 00:53:19 +00:00
"execution_count": 6,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [],
"source": [
"t = trange(10)"
]
},
{
"cell_type": "code",
2021-03-09 00:53:19 +00:00
"execution_count": 7,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0%| | 0/10 [00:00<?, ?it/s]\n",
" 0%| | 0/10 [00:00<?, ?it/s]\n"
]
}
],
"source": [
"print(t)\n",
"print(t.container)"
]
},
{
"cell_type": "code",
2021-03-09 00:53:19 +00:00
"execution_count": 8,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [],
"source": [
"for i in t:\n",
" pass"
]
},
{
"cell_type": "code",
2021-03-09 00:53:19 +00:00
"execution_count": 9,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100%|██████████| 10/10 [00:00<00:00, 169.05it/s]\n",
"100%|##########| 10/10 [00:00<00:00, 168.12it/s]\n"
]
}
],
"source": [
"print(t)\n",
"print(t.container)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# no total"
]
},
{
"cell_type": "code",
2021-03-09 00:53:19 +00:00
"execution_count": 10,
2021-03-08 23:53:50 +00:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"no total: 0it [00:00, ?it/s]\n",
"no total: 1it [00:00, 33.56it/s]\n"
]
}
],
"source": [
"with tqdm(desc=\"no total\") as t:\n",
" print(t)\n",
" t.update()\n",
" print(t)"
2021-03-08 22:26:04 +00:00
]
2021-03-09 00:53:19 +00:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# ncols"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 0%| | 0/10 [00:00<?, ?it/s]\n",
" 10%|███ | 1/10 [00:00<00:00, 32.29it/s]\n"
]
}
],
"source": [
"with trange(10, ncols=66) as t:\n",
" print(t)\n",
" for i in t:\n",
" if i == 1:\n",
" break\n",
" print(t)"
]
2021-03-08 22:26:04 +00:00
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:tqdm]",
"language": "python",
"name": "conda-env-tqdm-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython"
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}