Skip to content

Commit

Permalink
tqdm.autonotebook
Browse files Browse the repository at this point in the history
- adds documentation and `pandas()` example (#474)
- closes #443
  • Loading branch information
casperdcl committed Jun 3, 2018
1 parent 0307fd1 commit 97a9393
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,18 @@ light blue: no ETA); as demonstrated below.
|Screenshot-Jupyter2|
|Screenshot-Jupyter3|

It is also possible to let ``tqdm`` automatically choose between
console or notebook versions by using the ``autonotebook`` submodule:

.. code:: python
from tqdm.autonotebook import tqdm
tqdm.pandas()
Note that this will issue a ``TqdmExperimentalWarning`` if run in a notebook
since it is not meant to be possible to distinguish between ``jupyter notebook``
and ``jupyter console``.

Writing messages
~~~~~~~~~~~~~~~~

Expand Down
15 changes: 15 additions & 0 deletions tqdm/autonotebook/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
try:
from IPython import get_ipython
if 'IPKernelApp' not in get_ipython().config:
raise ImportError("console")
except:
from .._tqdm import tqdm, trange
else:
from .._tqdm_notebook import tqdm_notebook as tqdm
from .._tqdm_notebook import tnrange as trange
from .._tqdm import TqdmExperimentalWarning
from warnings import warn
warn("Using `tqdm.autonotebook.tqdm` in notebook mode."
" Use `tqdm.tqdm` instead to force console mode"
" (e.g. in jupyter console)", TqdmExperimentalWarning)
__all__ = ["tqdm", "trange"]

4 comments on commit 97a9393

@KOLANICH
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 The name is too long :(
2 IMHO this mode should be used by default

@casperdcl
Copy link
Member Author

@casperdcl casperdcl commented on 97a9393 Jul 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Don't see how we could shorten the name without being vague.
  2. Can't make default due to seemingly never resolvable warning (notebook frontends indistinguishable, as discussed in magic tqdm #443 (comment))

@KOLANICH
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see how we could shorten the name without being vague.

You already shorten with being vague: trange, tnrange

IMHO adding prefixes to functions is not a good idea.

Can't make default due to seemingly never resolvable warning (notebook frontends indistinguishable, as discussed in #443 (comment))

Anyway, in most cases user needs the solution working for both notebooks and console. Warning is unneeded and harmful. Instead problem description should be put into the faq.

BTW, the module doesn't go into a wheel.

@chengs
Copy link
Contributor

@chengs chengs commented on 97a9393 Sep 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, tqdm.auto is better than tqdm.autonotebook.
Similarly, tqdm.auto.trange and tqdm.auto.tqdm can be used.

Please sign in to comment.