Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

global name 'inf' is not defined

I have developed a function that was on its own in a script. I ran that script to place the function in my namespace. The line of code I have that was working fine is:

df.my_variable.replace([inf, -inf, nan, NaN], 0, inplace=True)

I have now moved this function into mymodule.py. I then try to run it:

import mymodule as mm
mm.myfun()

The line of code to replace inf, etc., now throws the following error:

global name 'inf' is not defined

I'm sure this is a legacy of developing interactively in IPython, but I'm stumped as to how I would define inf to make this work.

like image 218
BMichell Avatar asked Oct 16 '14 10:10

BMichell


People also ask

What is global name not defined in Python?

Python Nameerror name is not defined You will encounter a nameerror ( name is not defined) when a variable is not defined in the local or global scope. Or you used a function that wasn't defined anywhere in your program. For example, you will see this error if you try to print a variable that wasn't defined.

How do you fix NameError name is not defined?

The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.


1 Answers

Try this:

from numpy import inf
like image 111
Darth Kotik Avatar answered Sep 28 '22 15:09

Darth Kotik