[egenix-users] mx.DateTime bogus warning: "float where int
expected"
M.-A. Lemburg
mal at lemburg.com
Wed Sep 17 21:01:58 CEST 2003
Jim Vickroy wrote:
> I do not have an explanation, but the statement:
>
> dt = self.firstdate + self.mm * int(i)
>
> appears to be the source of this warning. The warning only appears the first
> time the statement is executed; thereafter, no warning is issued.
Right, that's a Python feature.
The cause of the problem seems to be that DateTime() constructor
expects integers as argument and that the code in RelativeDateTime
can generate floats as a result of refitting the values into proper
ranges.
Try adding this snippet in DateTime.py before line 585:
# Refit into proper ranges:
if month < 1 or month > 12:
month = month - 1
yeardelta, monthdelta = divmod(month, 12)
year = year + yeardelta
month = monthdelta + 1
# Make sure we have integers
year = int(year)
month = int(month)
day = int(day)
if self.weekday is None:
return DateTime(year, month, 1) + \
DateTimeDelta(day-1,hour,minute,second)
> python at sarcastic-horse.com wrote:
>
>
>>Hi-
>>
>>I'm getting a "DeprecationWarning: integer argument expected, got float"
>>warning with mx.DateTime and I can't figure out why. Can anyone help me
>>out?
>>
>>This code:
>>
>>import mx.DateTime
>>
>>class xLabeller:
>> def __init__(self, firstdate,fmt='%B, %Y'):
>> self.firstdate = firstdate
>> self.fmt = fmt
>> self.mm = mx.DateTime.RelativeDateTime(months=1)
>> def __call__(self, i):
>> dt = self.firstdate + self.mm * int(i)
>> return dt.Format(self.fmt)
>>
>>nov99 = mx.DateTime.Date(int(1999), int(11))
>>
>>xl = xLabeller(nov99)
>>print "xl2:"
>>print xl(int(3))
>>
>>Produces this warning:
>>
>>
>>>>>================================ RESTART ===========
>>>>>
>>
>>xl2:
>>C:\Python23\lib\site-packages\mx\DateTime\DateTime.py:585:
>>DeprecationWarning: integer argument expected, got float
>> return DateTime(year, month, 1) + \
>>February, 2000
>>
>>What is the story? I've wrapped every number in my program with int(). I
>>can't figure out what's triggering the warning.
>>
>>And, even stranger, the whole thing works fine at the python shell:
>>
>>
>>>>>import mx.DateTime
>>>>>mm = mx.DateTime.RelativeDateTime(months=1)
>>>>>nov99
>>
>><DateTime object for '1999-11-01 00:00:00.00' at 98dc20>
>>
>>>>>dt = nov99 + mm * 3
>>>>>dt.Format('%b, %y')
>>
>>'Feb, 00'
>>
>>What am I doing wrong?
>>
>>Thanks for the help.
>>
>>_______________________________________________________________________
>>eGenix.com User Mailing List http://www.egenix.com/
>>http://lists.egenix.com/mailman/listinfo/egenix-users
>
>
>
> _______________________________________________________________________
> eGenix.com User Mailing List http://www.egenix.com/
> http://lists.egenix.com/mailman/listinfo/egenix-users
--
Marc-Andre Lemburg
eGenix.com
Professional Python Software directly from the Source (#1, Sep 17 2003)
>>> Python/Zope Products & Consulting ... http://www.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::
More information about the egenix-users
mailing list