Returns which partitions to pair for the merge_asof algorithm and the bounds on which to split them up
(L, R)
| 179 | |
| 180 | |
| 181 | def pair_partitions(L, R): |
| 182 | """Returns which partitions to pair for the merge_asof algorithm and the |
| 183 | bounds on which to split them up |
| 184 | """ |
| 185 | result = [] |
| 186 | |
| 187 | n, m = len(L) - 1, len(R) - 1 |
| 188 | i, j = 0, -1 |
| 189 | while j + 1 < m and R[j + 1] <= L[i]: |
| 190 | j += 1 |
| 191 | J = [] |
| 192 | while i < n: |
| 193 | partition = max(0, min(m - 1, j)) |
| 194 | lower = R[j] if j >= 0 and R[j] > L[i] else None |
| 195 | upper = ( |
| 196 | R[j + 1] |
| 197 | if j + 1 < m |
| 198 | and (R[j + 1] < L[i + 1] or R[j + 1] == L[i + 1] and i == n - 1) |
| 199 | else None |
| 200 | ) |
| 201 | |
| 202 | J.append((partition, lower, upper)) |
| 203 | |
| 204 | i1 = i + 1 if j + 1 == m or (i + 1 < n and R[j + 1] >= L[i + 1]) else i |
| 205 | j1 = j + 1 if i + 1 == n or (j + 1 < m and L[i + 1] >= R[j + 1]) else j |
| 206 | if i1 > i: |
| 207 | result.append(J) |
| 208 | J = [] |
| 209 | elif i == n - 1 and R[j1] > L[n]: |
| 210 | result.append(J) |
| 211 | break |
| 212 | i, j = i1, j1 |
| 213 | |
| 214 | return result |
| 215 | |
| 216 | |
| 217 | def merge_asof_padded(left, right, prev=None, next=None, **kwargs): |