473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

years later DeprecationWarning

Here's the deal: I have to maintain this long gone guy's programs and
lately they've been saying
../north_pass.py:14: DeprecationWarning: integer argument expected, got float
fl=range(1000*(math.floor(25000*f2m/1000)),46000*f2m,1000)

As I don't know python, I tried sticking an int( ) in various places
in that line but couldn't get whatever is bothering python to shut up. Help.

(That long-gone guy is actually me, according to the notes in the program.
However those brain cells are long gone now, so it might as well not be me.)

Mar 22 '06 #1
5 1754

"Dan Jacobson" <ji*****@jidanni.org> wrote in message
news:87************@jidanni.org...
Here's the deal: I have to maintain this long gone guy's programs and
lately they've been saying
./north_pass.py:14: DeprecationWarning: integer argument expected, got
float
fl=range(1000*(math.floor(25000*f2m/1000)),46000*f2m,1000)


The warning is from the range function. If f2m is float, so too the first
2 args. Either convert f2m to int first or both args to int. The second
is what happens now. A long too large to convert to int also raises an
error.

Terry Jan Reedy

Mar 22 '06 #2
Two things:
1) math.floor returns a float, not an int. Doing an int() conversion on
a float already floors the value, anyways. Try replacing
math.floor(...) with int(...)
e.g.
math.floor(5.9) 5.0 int(5.9)

5

2) What kind of data is in f2m? If f2m is a float, you will get float
values in the expressions that f2m is a multiplicand.

Mar 22 '06 #3
Dan Jacobson <ji*****@jidanni.org> writes:
Here's the deal: I have to maintain this long gone guy's programs and
lately they've been saying
./north_pass.py:14: DeprecationWarning: integer argument expected, got float
fl=range(1000*(math.floor(25000*f2m/1000)),46000*f2m,1000)
You haven't shown us the value of all the terms there; specifically,
we don't know what value has been bound to 'f2m'.

Ideally, this code would have been written to be more easily readable
and explicit. This is an illustration that it's never too late to do
so, and that it can help you understand what the heck is going wrong.

Replace those literals with named constants, that indicate what the
heck they are.

import math
f2m = 1.0 # assuming this is where the float value gets introduced
some_increment_thing = 1000
some_starting_count = 25
some_ending_count = 46
some_starting_scale = some_starting_count * some_increment_thing
some_ending_scale = some_ending_count * some_increment_thing
fl = range(some_increment_thing*(math.floor(some_starti ng_scale*f2m/some_increment_thing)), some_ending_scale*f2m, some_increment_thing)

Use names that make sense in the problem domain, of course. The idea
is to not keep the reader (that's you, months or years from now)
guessing why '1000' is used three times, or whether it's mere
coincidence that all the other values seem to be multiples of 1000, or
whether each of those 1000s is meant to be the same thing, or whether
one of them can change, etc.

Split out this mess into separate operations, so you can see what's
failing.

range_start = some_increment_thing * math.floor(some_starting_scale*f2m/some_increment_thing)
range_limit = some_ending_scale * f2m
fl = range(range_start, range_limit, some_increment_thing)

That will get you closer to the point of knowing what's causing the
error. It will also (if you've chosen meaningful names) make the code
much more understandable; and perhaps even give you ways to re-think
the algorithm used.
(That long-gone guy is actually me, according to the notes in the
program. However those brain cells are long gone now, so it might
as well not be me.)


One should always write code for some unknown future person, months or
years after the original context of the problem is forgotten, to
understand, without the benefit of your explanation. As you've found,
that person is most frequently oneself.

--
\ "Friendship is born at that moment when one person says to |
`\ another, 'What! You too? I thought I was the only one!'" -- |
_o__) C.S. Lewis |
Ben Finney

Mar 22 '06 #4
> (That long-gone guy is actually me, according to the notes in the program.
However those brain cells are long gone now, so it might as well not be me.)


I had a great long laugh with this bit. I guess it's because I can
relate so well :)

Mar 23 '06 #5
On Wed, 22 Mar 2006 13:59:00 -0800, Chris Lasher wrote:
Two things:
1) math.floor returns a float, not an int. Doing an int() conversion on
a float already floors the value, anyways.


No it doesn't, or rather, int() is only equivalent to floor() if you limit
the input to non-negative numbers:

int(-2.2) => -2, but floor(-2.2) should give -3.

The standard definition of floor() and ceil() are:

floor(x) = maximum integer n such that n <= x
ceil(x) = minimum integer n such that n >= x

or as Python functions:

def floor(x):
"Returns the maximum integer less than or equal to x"
if x >= 0:
return int(x)
else:
if x % 1: return int(x)-1
else: return int(x)

def ceil(x):
"Returns the minimum integer greater than or equal to x"
return -floor(-x)

or even simpler:

from math import floor, ceil

(Caution: the functions defined in the math module return the floor and
ceiling as floats, not int, so you may want to wrap them in a call to int.)

--
Steven.

Mar 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Pierre Rouleau | last post by:
Hi all! I am using Python 2.3.1 on Win32 (NT, 2000). Whenever a file imports the standard tempfile module, Python 2.3.1 issues the following warning: C:\Python23\lib\fcntl.py:7:...
0
by: Ben Finney | last post by:
Howdy all, I'm using a library that uses SmartCookie. In Python 2.3, that gives this warning: /usr/lib/python2.3/Cookie.py:712: DeprecationWarning: Cookie/SmartCookie class is insecure; do...
77
by: Gerrit Holl | last post by:
Hi, the <> inequality test operator has been deprecated for a loooooong time. Is there a reason that it doesn't trigger a DeprecationWarning? $ python2.2 -Wall -c "print 0 <> 0" 0 $...
2
by: ahsan Imam | last post by:
Hello All, I have this file and when I import the file in the python interpretor I get the following error: "__main__:1: DeprecationWarning: Non-ASCII character '\xc0' in file trans.py on...
37
by: asj | last post by:
interesting read from eweek about the dying hope surrounding .net http://www.eweek.com/article2/0,,1184728,00.asp The end of last month marked the third anniversary of Microsoft's launch of...
2
by: jau | last post by:
Hi co-listers! I have been off Python for 2 years and now, that i'm used to Eclipse and Java, I decided to start a project with Python to refresh skills this time using Eclipse and TrueStudio....
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
7
by: John Nagle | last post by:
How do I suppress "DeprecationWarning: Old style callback, use cb_func(ok, store) instead". A library is triggering this message, the library is being fixed, but I need to make the message...
4
by: oliver | last post by:
Hey There, Sorry if I am missing something here, but I get a DeprecationWarning when importing a list which has some unicode characters in it (it's a list of countries -- it's being raised on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.