Closed stefraynaud closed 6 years ago
I think it is linked to bug #8 This breaks alot of code still running under python2.
I hope nothing is broken in the python2 version! I have not installed v8 yet
@stefraynaud yes I think @dnadeau4 broke this while porting to 3.0, please use cmp
function on the objects. @dnadeau4 any chance to re-enable this? Can we at least make it fail rather than giving wrong answers?
It's almost impossible to identify all cdtime comparisons in tens of thousands of code lines. It should be as difficult as to convert everybody quickly to python3. :)
@stefraynaud agreed! Let's wait and hear @dnadeau4 reasoning on why this is gone.
@stefraynaud yes you need to use the method cmp attached on objects, sorry my original post was misleading. @dnadeau4 it looks like this needs to be fixed.
@doutriaux1 no way to re-enable this. "cmp" no longer exist in python3. All tests pass, maybe you could write better tests.
@dnadeau4 maybe i could you're right. But now @stefraynaud gave you good tests, so thanks.
It might be a bug in python. I am not sure what is going on with python2. I cannot bring the overload into the richcompare()
function in the debugger. Maybe the python 2 module is not setup right.
python2
In [19]: cdtime.comptime(2000)<cdtime.comptime(2001)
Out[19]: False
In [20]: cdtime.comptime(2000)<cdtime.comptime(2001)
Out[20]: True
In [21]: cdtime.comptime(2000)<cdtime.comptime(2001)
Out[21]: False
In [22]: cdtime.comptime(2000)<cdtime.comptime(2001)
Out[22]: True
In [23]: cdtime.comptime(2000)<cdtime.comptime(2001)
Out[23]: False
In [24]: aa = cdtime.comptime(2000)
In [25]: bb = cdtime.comptime(2001)
...:
In [26]: aa < bb
Out[26]: True
In [27]: aa < bb
Out[27]: True
In [28]: aa < bb
Out[28]: True
In [29]: aa < bb
Out[29]: True
cmp which is python2 ways to do compare works.
In [33]: cdtime.comptime(2000).cmp(cdtime.comptime(2001))
Out[33]: -1
In [34]: cdtime.comptime(2001).cmp(cdtime.comptime(2000))
Out[34]: 1
Not sure if that works on the MAC, need testing... 432ddb9faab79d6a5a6863b9758c09218152090e
New test pass on OSX and python https://github.com/CDAT/cdtime/pull/19
I had to set 2 different comparisons tp_compare
for python 2 and tp_richcompare
for python 3.
Python 2 calls tp_compare
when using <, >,=,..
operators.
Python 3 calls tp_richcompare
.
Actually,
Python 2 will call tp_richcompare
if you use __lt__, __eq__, ...
, but will call tp_compare
if you use <, ==
.
So a<b
is a different funtion call than a.__lt__(b)
in python 2, but the same function call in python 3.
@stefraynaud Your issue has been solved and merged to master. Although @doutriaux1 test found conversion issues in libcdms
. I have not pin point the source of that error yet. The year pass is YYYY-XX
:wow:
Hi, time comparisons seem now buggy. Here are various tests:
What changed?