@@ -660,8 +660,10 @@ def left_join_indexer_unique_%(name)s(ndarray[%(c_type)s] left,
660
660
661
661
"""
662
662
663
- left_join_template = """@cython.wraparound(False)
664
- @cython.boundscheck(False)
663
+ # @cython.wraparound(False)
664
+ # @cython.boundscheck(False)
665
+
666
+ left_join_template = """
665
667
def left_join_indexer_%(name)s(ndarray[%(c_type)s] left,
666
668
ndarray[%(c_type)s] right):
667
669
'''
@@ -691,9 +693,12 @@ def left_join_indexer_%(name)s(ndarray[%(c_type)s] left,
691
693
if lval == rval:
692
694
count += 1
693
695
if i < nleft - 1:
694
- i += 1
695
- if left[i] != rval:
696
+ if j < nright - 1 and right[j + 1] == rval:
696
697
j += 1
698
+ else:
699
+ i += 1
700
+ if left[i] != rval:
701
+ j += 1
697
702
elif j < nright - 1:
698
703
j += 1
699
704
if lval != right[j]:
@@ -725,6 +730,7 @@ def left_join_indexer_%(name)s(ndarray[%(c_type)s] left,
725
730
result[count] = left[i]
726
731
i += 1
727
732
count += 1
733
+ break
728
734
729
735
lval = left[i]
730
736
rval = right[j]
@@ -735,9 +741,12 @@ def left_join_indexer_%(name)s(ndarray[%(c_type)s] left,
735
741
result[count] = lval
736
742
count += 1
737
743
if i < nleft - 1:
738
- i += 1
739
- if left[i] != rval:
744
+ if j < nright - 1 and right[j + 1] == rval:
740
745
j += 1
746
+ else:
747
+ i += 1
748
+ if left[i] != rval:
749
+ j += 1
741
750
elif j < nright - 1:
742
751
j += 1
743
752
if lval != right[j]:
@@ -779,31 +788,34 @@ def inner_join_indexer_%(name)s(ndarray[%(c_type)s] left,
779
788
j = 0
780
789
count = 0
781
790
if nleft > 0 and nright > 0:
782
- lval = left[0]
783
- rval = right[0]
784
791
while True:
792
+ if i == nleft:
793
+ break
794
+ if j == nright:
795
+ break
796
+
797
+ lval = left[i]
798
+ rval = right[j]
785
799
if lval == rval:
786
800
count += 1
787
801
if i < nleft - 1:
788
- i += 1
789
- lval = left[i]
802
+ if j < nright - 1 and right[j + 1] == rval:
803
+ j += 1
804
+ else:
805
+ i += 1
806
+ if left[i] != rval:
807
+ j += 1
790
808
elif j < nright - 1:
791
809
j += 1
792
- rval = right[j]
810
+ if lval != right[j]:
811
+ i += 1
793
812
else:
813
+ # end of the road
794
814
break
795
815
elif lval < rval:
796
- if i < nleft - 1:
797
- i += 1
798
- lval = left[i]
799
- else:
800
- break
816
+ i += 1
801
817
else:
802
- if j < nright - 1:
803
- j += 1
804
- rval = right[j]
805
- else:
806
- break
818
+ j += 1
807
819
808
820
# do it again now that result size is known
809
821
@@ -815,34 +827,37 @@ def inner_join_indexer_%(name)s(ndarray[%(c_type)s] left,
815
827
j = 0
816
828
count = 0
817
829
if nleft > 0 and nright > 0:
818
- lval = left[0]
819
- rval = right[0]
820
830
while True:
831
+ if i == nleft:
832
+ break
833
+ if j == nright:
834
+ break
835
+
836
+ lval = left[i]
837
+ rval = right[j]
821
838
if lval == rval:
822
839
lindexer[count] = i
823
840
rindexer[count] = j
824
841
result[count] = rval
825
842
count += 1
826
843
if i < nleft - 1:
827
- i += 1
828
- lval = left[i]
844
+ if j < nright - 1 and right[j + 1] == rval:
845
+ j += 1
846
+ else:
847
+ i += 1
848
+ if left[i] != rval:
849
+ j += 1
829
850
elif j < nright - 1:
830
851
j += 1
831
- rval = right[j]
852
+ if lval != right[j]:
853
+ i += 1
832
854
else:
855
+ # end of the road
833
856
break
834
857
elif lval < rval:
835
- if i < nleft - 1:
836
- i += 1
837
- lval = left[i]
838
- else:
839
- break
858
+ i += 1
840
859
else:
841
- if j < nright - 1:
842
- j += 1
843
- rval = right[j]
844
- else:
845
- break
860
+ j += 1
846
861
847
862
return result, lindexer, rindexer
848
863
@@ -883,9 +898,12 @@ def outer_join_indexer_%(name)s(ndarray[%(c_type)s] left,
883
898
if lval == rval:
884
899
count += 1
885
900
if i < nleft - 1:
886
- i += 1
887
- if left[i] != rval:
901
+ if j < nright - 1 and right[j + 1] == rval:
888
902
j += 1
903
+ else:
904
+ i += 1
905
+ if left[i] != rval:
906
+ j += 1
889
907
elif j < nright - 1:
890
908
j += 1
891
909
if lval != right[j]:
@@ -947,14 +965,18 @@ def outer_join_indexer_%(name)s(ndarray[%(c_type)s] left,
947
965
result[count] = lval
948
966
count += 1
949
967
if i < nleft - 1:
950
- i += 1
951
- if left[i] != rval:
968
+ if j < nright - 1 and right[j + 1] == rval:
952
969
j += 1
970
+ else:
971
+ i += 1
972
+ if left[i] != rval:
973
+ j += 1
953
974
elif j < nright - 1:
954
975
j += 1
955
976
if lval != right[j]:
956
977
i += 1
957
978
else:
979
+ # end of the road
958
980
break
959
981
elif lval < rval:
960
982
lindexer[count] = i
0 commit comments