49

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?

Sahand
  • 7,980
  • 23
  • 69
  • 137
  • 3
    Possible duplicate of [Stop IPython Notebook from printing warnings / status updates to terminal](https://stackoverflow.com/questions/33572118/stop-ipython-notebook-from-printing-warnings-status-updates-to-terminal) – Antoine Boisier-Michaud Feb 16 '18 at 14:32

6 Answers6

107

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')
Ramon Crehuet
  • 3,679
  • 1
  • 22
  • 37
24

Try this:

import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')
mrasoolmirza
  • 787
  • 1
  • 6
  • 22
12

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
fhchl
  • 711
  • 8
  • 18
1

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))
1

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()
Matt
  • 1,196
  • 1
  • 9
  • 22
0

Just run this snippet at the top of your code:

!pip install shutup
##At the top of the code
import shutup;
shutup.please()
mufassir
  • 406
  • 5
  • 16