56

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?

1

6 Answers 6

119

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')
Sign up to request clarification or add additional context in comments.

2 Comments

This should be the validated answer !
doesn't work for me (nor do any other answers), see here: stackoverflow.com/a/69544407/5125264
25

Try this:

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

Comments

13

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

Comments

4

Just run this snippet at the top of your code:

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

Comments

2

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.