Python Forum
cannot convert float infinity to integer error despite rounding off floats
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cannot convert float infinity to integer error despite rounding off floats
#1

So here's the full error information
Error:
Traceback (most recent call last): File "<ipython-input-41-862883395604>", line 1, in <module> runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Intervention Functions.py', wdir='C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction') File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile execfile(filename, namespace) File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc) File "C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Intervention Functions.py", line 98, in <module> ax.plot(x, yFunction(initialPop, popGrowth), 'p-', lw=1, alpha=0.6, label='Major Graph') File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 1377, in plot self.autoscale_view(scalex=scalex, scaley=scaley) File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 1984, in autoscale_view y0, y1 = ylocator.view_limits(y0, y1) File "C:\Python27\lib\site-packages\matplotlib\ticker.py", line 1375, in view_limits return np.take(self.bin_boundaries(dmin, dmax), [0, -1]) File "C:\Python27\lib\site-packages\matplotlib\ticker.py", line 1347, in bin_boundaries extra_bins = int(divmod((best_vmax - vmax), step)[0]) OverflowError: cannot convert float infinity to integer
And here's the code:
def yFunction(initialPop, popGrowth):
    y=initialPop
    yList = np.array([])
    x=0
    while x < 400:
        yList = np.append(yList, y)
        y = (y * np.exp(popGrowth * (x/4))) - (newsDiscussion(1, 20, x, 0.0015, 0.003, 0.55)*y)-(Tax2(156, 160, x, 0.05775, 0.1155, 0.55)*y)-(Tax1(80, 84, x, 0.77, 0.154, 0.55)*y)-(runVeganuaryMain(x)*y)
        y = round(y, 5)
        #y = newsDiscussion(1, 20, x, 0.0015, 0.003, 0.55)+(Tax2(156, 160, x, 0.05775, 0.1155, 0.55)*y)+(Tax1(80, 84, x, 0.77, 0.154, 0.55)*y)+(runVeganuaryMain(x)*y)
        x = x + 0.1
    return yList
yList = yFunction(initialPop, popGrowth)
print(yList)
    


x= np.linspace(0, 400, num=4000)
ax.set_title('Decrease in People Who Consume Animals ')
ax.set_xlabel('$Quarter$')
ax.set_ylabel('$Population$')
ax.plot(x, yFunction(initialPop, popGrowth), 'p-', lw=1, alpha=0.6, label='Major Graph')
Can anyone tell me what's causing this error?

So I figured out how to round the variables, but the function I used returns a string. Easy fix right? Just use Int()? Apparently not. My program is giving me a new error.
def yFunction(initialPop, popGrowth):
    y=initialPop
    yList = np.array([])
    x=0
    while x < 400:
        yList = np.append(yList, y)
        y = (y * np.exp(popGrowth * (x/4))) - (newsDiscussion(1, 20, x, 0.0015, 0.003, 0.55)*y)-(Tax2(156, 160, x, 0.05775, 0.1155, 0.55)*y)-(Tax1(80, 84, x, 0.77, 0.154, 0.55)*y)-(runVeganuaryMain(x)*y)
        y = int(format(y, '.5f'))
        x = x + 0.1
    return yList
yList = yFunction(initialPop, popGrowth)
print(yList)
    


x= np.linspace(0, 400, num=4000)
ax.set_title('Decrease in People Who Consume Animals ')
ax.set_xlabel('$Quarter$')
ax.set_ylabel('$Population$')
ax.plot(x, yFunction(initialPop, popGrowth), 'p-', lw=1, alpha=0.6, label='Major Graph')
Error:
Traceback (most recent call last): File "<ipython-input-52-862883395604>", line 1, in <module> runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Intervention Functions.py', wdir='C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction') File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile execfile(filename, namespace) File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc) File "C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Intervention Functions.py", line 81, in <module> yList = yFunction(initialPop, popGrowth) File "C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Intervention Functions.py", line 78, in yFunction y = int(format(y, '.5f')) ValueError: invalid literal for int() with base 10: '326300000.00000'
Reply


Messages In This Thread
cannot convert float infinity to integer error despite rounding off floats - by Afterdarkreader - Dec-14-2017, 07:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  float object can't be interpreted as an integer t23 2 1,109 Jan-18-2025, 07:36 PM
Last Post: deanhystad
  python calculate float plus float is incorrect? sirocawa 6 2,384 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  When is it safe to compare (==) two floats? Radical 4 3,015 Nov-12-2023, 11:53 AM
Last Post: PyDan
  need help rounding joseph202020 7 2,849 Feb-21-2023, 08:13 PM
Last Post: joseph202020
  convert string to float in list jacklee26 6 3,720 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  openpyxl convert data to float jacklee26 13 12,915 Nov-19-2022, 11:59 AM
Last Post: deanhystad
  from numpy array to csv - rounding SchroedingersLion 6 6,793 Nov-14-2022, 09:09 PM
Last Post: deanhystad
  Convert SQLite Fetchone() Result to float for Math Extra 13 6,864 Aug-02-2022, 01:12 PM
Last Post: deanhystad
  KivyMD App to APK Convert Error Nick_MC 0 3,870 Jul-18-2022, 08:59 AM
Last Post: Nick_MC
Star Infinity loop edek121 0 45,102 Jun-05-2022, 12:51 PM
Last Post: edek121

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020