Skip to content

Commit 60b7d04

Browse files
committed
BUG: fix infinite loop on win32/64
1 parent 805ab79 commit 60b7d04

File tree

3 files changed

+41
-45
lines changed

3 files changed

+41
-45
lines changed

pandas/src/generate_code.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ def left_join_indexer_%(name)s(ndarray[%(c_type)s] left,
680680
j = 0
681681
count = 0
682682
if nleft > 0:
683-
while True:
683+
while i < nleft:
684684
if j == nright:
685685
count += nleft - i
686686
break
@@ -703,11 +703,9 @@ def left_join_indexer_%(name)s(ndarray[%(c_type)s] left,
703703
break
704704
elif lval < rval:
705705
count += 1
706-
if i < nleft:
707-
i += 1
706+
i += 1
708707
else:
709-
if j < nright:
710-
j += 1
708+
j += 1
711709
712710
# do it again now that result size is known
713711
@@ -752,11 +750,9 @@ def left_join_indexer_%(name)s(ndarray[%(c_type)s] left,
752750
rindexer[count] = -1
753751
result[count] = left[i]
754752
count += 1
755-
if i < nleft:
756-
i += 1
753+
i += 1
757754
else:
758-
if j < nright:
759-
j += 1
755+
j += 1
760756
761757
return result, lindexer, rindexer
762758

pandas/src/generated.pyx

+20-36
Original file line numberDiff line numberDiff line change
@@ -2741,7 +2741,7 @@ def left_join_indexer_float64(ndarray[float64_t] left,
27412741
j = 0
27422742
count = 0
27432743
if nleft > 0:
2744-
while True:
2744+
while i < nleft:
27452745
if j == nright:
27462746
count += nleft - i
27472747
break
@@ -2764,11 +2764,9 @@ def left_join_indexer_float64(ndarray[float64_t] left,
27642764
break
27652765
elif lval < rval:
27662766
count += 1
2767-
if i < nleft:
2768-
i += 1
2767+
i += 1
27692768
else:
2770-
if j < nright:
2771-
j += 1
2769+
j += 1
27722770

27732771
# do it again now that result size is known
27742772

@@ -2813,11 +2811,9 @@ def left_join_indexer_float64(ndarray[float64_t] left,
28132811
rindexer[count] = -1
28142812
result[count] = left[i]
28152813
count += 1
2816-
if i < nleft:
2817-
i += 1
2814+
i += 1
28182815
else:
2819-
if j < nright:
2820-
j += 1
2816+
j += 1
28212817

28222818
return result, lindexer, rindexer
28232819

@@ -2841,7 +2837,7 @@ def left_join_indexer_object(ndarray[object] left,
28412837
j = 0
28422838
count = 0
28432839
if nleft > 0:
2844-
while True:
2840+
while i < nleft:
28452841
if j == nright:
28462842
count += nleft - i
28472843
break
@@ -2864,11 +2860,9 @@ def left_join_indexer_object(ndarray[object] left,
28642860
break
28652861
elif lval < rval:
28662862
count += 1
2867-
if i < nleft:
2868-
i += 1
2863+
i += 1
28692864
else:
2870-
if j < nright:
2871-
j += 1
2865+
j += 1
28722866

28732867
# do it again now that result size is known
28742868

@@ -2913,11 +2907,9 @@ def left_join_indexer_object(ndarray[object] left,
29132907
rindexer[count] = -1
29142908
result[count] = left[i]
29152909
count += 1
2916-
if i < nleft:
2917-
i += 1
2910+
i += 1
29182911
else:
2919-
if j < nright:
2920-
j += 1
2912+
j += 1
29212913

29222914
return result, lindexer, rindexer
29232915

@@ -2941,7 +2933,7 @@ def left_join_indexer_int32(ndarray[int32_t] left,
29412933
j = 0
29422934
count = 0
29432935
if nleft > 0:
2944-
while True:
2936+
while i < nleft:
29452937
if j == nright:
29462938
count += nleft - i
29472939
break
@@ -2964,11 +2956,9 @@ def left_join_indexer_int32(ndarray[int32_t] left,
29642956
break
29652957
elif lval < rval:
29662958
count += 1
2967-
if i < nleft:
2968-
i += 1
2959+
i += 1
29692960
else:
2970-
if j < nright:
2971-
j += 1
2961+
j += 1
29722962

29732963
# do it again now that result size is known
29742964

@@ -3013,11 +3003,9 @@ def left_join_indexer_int32(ndarray[int32_t] left,
30133003
rindexer[count] = -1
30143004
result[count] = left[i]
30153005
count += 1
3016-
if i < nleft:
3017-
i += 1
3006+
i += 1
30183007
else:
3019-
if j < nright:
3020-
j += 1
3008+
j += 1
30213009

30223010
return result, lindexer, rindexer
30233011

@@ -3041,7 +3029,7 @@ def left_join_indexer_int64(ndarray[int64_t] left,
30413029
j = 0
30423030
count = 0
30433031
if nleft > 0:
3044-
while True:
3032+
while i < nleft:
30453033
if j == nright:
30463034
count += nleft - i
30473035
break
@@ -3064,11 +3052,9 @@ def left_join_indexer_int64(ndarray[int64_t] left,
30643052
break
30653053
elif lval < rval:
30663054
count += 1
3067-
if i < nleft:
3068-
i += 1
3055+
i += 1
30693056
else:
3070-
if j < nright:
3071-
j += 1
3057+
j += 1
30723058

30733059
# do it again now that result size is known
30743060

@@ -3113,11 +3099,9 @@ def left_join_indexer_int64(ndarray[int64_t] left,
31133099
rindexer[count] = -1
31143100
result[count] = left[i]
31153101
count += 1
3116-
if i < nleft:
3117-
i += 1
3102+
i += 1
31183103
else:
3119-
if j < nright:
3120-
j += 1
3104+
j += 1
31213105

31223106
return result, lindexer, rindexer
31233107

pandas/tests/test_tseries.py

+16
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ def test_outer_join_indexer():
124124
assert_almost_equal(ares, aexp)
125125
assert_almost_equal(bres, bexp)
126126

127+
a = np.array([5], dtype=np.int64)
128+
b = np.array([5], dtype=np.int64)
129+
130+
index, ares, bres = algos.outer_join_indexer_int64(a, b)
131+
assert_almost_equal(index, [5])
132+
assert_almost_equal(ares, [0])
133+
assert_almost_equal(bres, [0])
134+
127135
def test_left_join_indexer():
128136
a = np.array([1, 2, 3, 4, 5], dtype=np.int64)
129137
b = np.array([0, 3, 5, 7, 9], dtype=np.int64)
@@ -137,6 +145,14 @@ def test_left_join_indexer():
137145
assert_almost_equal(ares, aexp)
138146
assert_almost_equal(bres, bexp)
139147

148+
a = np.array([5], dtype=np.int64)
149+
b = np.array([5], dtype=np.int64)
150+
151+
index, ares, bres = algos.left_join_indexer_int64(a, b)
152+
assert_almost_equal(index, [5])
153+
assert_almost_equal(ares, [0])
154+
assert_almost_equal(bres, [0])
155+
140156

141157
def test_is_lexsorted():
142158
failure = [

0 commit comments

Comments
 (0)