Sahand
Sahand

Reputation: 8360

Disable warnings in jupyter notebook

I'm getting this warning in jupyter notebook.

/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:10: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.
  # Remove the CWD from sys.path while we load stuff.
/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:11: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.
  # This is added back by InteractiveShellApp.init_path()

It's annoying because it shows up in every run I do:

enter image description here

How do I fix or disable it?

Upvotes: 55

Views: 107725

Answers (6)

mufassir
mufassir

Reputation: 562

Just run this snippet at the top of your code:

!pip install shutup
##At the top of the code
import shutup;
shutup.please()

Upvotes: 3

Matt
Matt

Reputation: 1284

None of these answers work if you are arriving from google, I finally found a solution (credit to this answer)

from IPython.utils import io

with io.capture_output() as captured:
    foo()

Upvotes: 2

fhchl
fhchl

Reputation: 751

You can also suppress warnings just for some lines of code:

import warnings

def function_that_warns():
    warnings.warn("deprecated", DeprecationWarning)

with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    function_that_warns()  # this will not show a warning

Upvotes: 12

mrasoolmirza
mrasoolmirza

Reputation: 897

Try this:

import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')

Upvotes: 25

Ramon Crehuet
Ramon Crehuet

Reputation: 4017

If you are sure your code is correct and simple want to get rid of this warning and all other warnings in the notebook do the following:

import warnings
warnings.filterwarnings('ignore')

Upvotes: 118

Markus Eisenbach
Markus Eisenbach

Reputation: 137

You will get this warning if you pass an argument as float, that should be an integer.

E.g., in the following example, num should be an integer, but is passed as float:

import numpy as np
np.linspace(0, 10, num=3.0)

This prints the warning you got:

ipykernel_launcher.py:2: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.

Since parts of your code are missing, I cannot figure out, which parameter should be passed as integer, but the following example shows how to fix this:

import numpy as np
np.linspace(0, 10, num=int(3.0))

Upvotes: 1

Related Questions