[Python-bugs-list] [ python-Bugs-457399 ] bisect module broken in 2.1.1 ?
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 31 Aug 2001 14:05:04 -0700
Bugs item #457399, was opened at 2001-08-31 13:40
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=457399&group_id=5470
Category: Python Library
>Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Daniel Mahler (dmahler)
>Assigned to: Tim Peters (tim_one)
Summary: bisect module broken in 2.1.1 ?
Initial Comment:
given the function:
def findClause(C, SS):
for j in range(1,len(SS)):
assert SS[j-1] <= SS[j], (j, SS[j-1], SS[j])
C2 = map(abs, C)
i = bisect.bisect_left(C2, SS)
assert C2 >= SS[i], (i, C, C2, [C3 for C3 in SS if
C3 <= C2], SS[0:4])
return i
I get:
i = findClause(C, SS)
File "/home/mahler/code/scripts/oshl.py", line 248,
in findClause
assert C2 >= SS[i], (i, C, C2, [C3 for C3 in SS if
C3 <= C2], SS[0:4])
AssertionError: (3, [5, -2, 1], [5, 2, 1], [], [[5, 3,
1], [5, 3, 2], [6, 4, 2], [7, 3, 2]])
As far as I can tell this must be a bug:
the first loop ensures that the list is sorted.
It is the bottom asertion that is throwing the
exception
The values returned with the exception show that we
were
looking for an element smaller than any in the list.
I would therefore expect 0 to be returned,
but I get 3.
Daniel Mahler
mahler@cyc.com
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2001-08-31 14:05
Message:
Logged In: YES
user_id=31435
It looks like you passed arguments to bisect in the wrong
order. Try
i = bisect.bisect_left(SS, C2)
instead. As is, you're looking for the position within
list [5, 2, 1] to insert element SS (the opposite of what I
expect you intended), and since any list *happens to*
compare greater than any integer in 2.1, the list SS
belongs at position C2[3].
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=457399&group_id=5470