Notebook: problem with warnings module

Created on 1 Mar 2017  路  15Comments  路  Source: jupyter/notebook

The warnings module is behaving in unexpected ways, but only within a notebook. I'm using python 3.6.0.final.0 on windows 64 with notebook 4.4.1, jupyter_client 5.0.0, and jupyter_core 4.3.0, and ipython 5.3.0.

If I run ipython from the console and run the following code one line at a time:

import warnings
warnings.filterwarnings(action='ignore')
x = 1 + 1
warnings.resetwarnings()
x = 1 + 1

Everything runs as expected and there are no warnings displayed.

However, if I run the same code in a notebook with one line per cell, the following warning is displayed after cell 4 and again after cell 5:

C:\Anaconda\lib\json\encoder.py:199: DeprecationWarning: Interpreting naive datetime as local 2017-02-28 21:20:58.170463. Please add timezone info to timestamps.
  chunks = self.iterencode(o, _one_shot=True)

Essentially, any time after running warnings.resetwarnings() at any point in a notebook, every subsequent cell execution displays that warning message with the current timestamp.

Most helpful comment

I am getting these warnings all in almost all cells.

Not sure why it happens.

All 15 comments

That's a warning coming from some of the kernel code. It's hidden by default, but when you reset the warning filters, you'll see it. Terminal IPython doesn't use the code path that causes the warning.

Thanks @takluyver. This is new behavior -- the same code did not show the warning in the previous notebook/jupyter version... if I need to temporarily filterwarnings in the latest version notebook, how do I return to the original level when I'm done?

It's a new warning ;-)

Maybe try this: https://docs.python.org/3/library/warnings.html#temporarily-suppressing-warnings

Yes that works. For reference, here's the code that works with Python 3.6 to temporarily suppress warnings in a notebook, without having to explicitly reset the warning filters when you're done:

import warnings
with warnings.catch_warnings():
    warnings.simplefilter('ignore')
    # do something here and its warning is suppressed

I am getting these warnings all in almost all cells.

Not sure why it happens.

Same here. Just updated my python packages to their latest versions and now getting these warning in every cell.

It's especially bad when you connect to a few hundred ipyparallel engines and this warning is printed many many times.

Same issue here. It started when I updated the python packages as well.

Any pointers to this?

I'm experiencing this as well in my notebooks. I'm not sure if this is the repository that needs to fix the issue but it seems to be most appropriate.

@gboeing Do you mind re-opening this so it becomes a bit more visible?

Same issue

+1

For people seeing this, what's pip list or conda list? https://github.com/ipython/ipykernel/pull/239 should fix it for people in notebooks.

@basnijholt when you see this with ipyparallel, what version do you have? Do you have an ipyparallel snippet that reproduces it? 6.0 should have resolved any na茂ve datetimes.

@minrk python 3.6.1.final.0

ipykernel                 4.6.0                    py36_0    conda-forge
ipython                   5.3.0                    py36_0    conda-forge
ipython_genutils          0.2.0                    py36_0    conda-forge
jupyter_client            5.0.1                    py36_0    conda-forge
jupyter_core              4.3.0                    py36_0    conda-forge
nbconvert                 5.1.1                    py36_1    conda-forge
nbformat                  4.2.0                    py36_0    conda-forge
notebook                  5.0.0                    py36_0    conda-forge

These warnings should be fixed with ipykernel 4.6.1, which is out on PyPI and should be up on conda-forge within a day or so.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonatanblue picture jonatanblue  路  3Comments

mmngreco picture mmngreco  路  3Comments

mikepqr picture mikepqr  路  3Comments

arilwan picture arilwan  路  3Comments

fonnesbeck picture fonnesbeck  路  3Comments