Skip to content

Commit

Permalink
Simplified get_blkno_indexers (#32645)
Browse files Browse the repository at this point in the history
Co-authored-by: Parallels <parallels@debian-gnu-linux-vm.localdomain>
  • Loading branch information
WillAyd and Parallels authored Mar 15, 2020
1 parent e7e5b61 commit 41322cf
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cython
from collections import defaultdict
from cython import Py_ssize_t

from cpython.slice cimport PySlice_GetIndicesEx
Expand Down Expand Up @@ -373,8 +374,7 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True):
Py_ssize_t i, start, stop, n, diff

object blkno
list group_order
dict group_dict
object group_dict = defaultdict(list)
int64_t[:] res_view

n = blknos.shape[0]
Expand All @@ -395,28 +395,16 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True):

yield cur_blkno, slice(start, n)
else:
group_order = []
group_dict = {}

for i in range(1, n):
if blknos[i] != cur_blkno:
if cur_blkno not in group_dict:
group_order.append(cur_blkno)
group_dict[cur_blkno] = [(start, i)]
else:
group_dict[cur_blkno].append((start, i))
group_dict[cur_blkno].append((start, i))

start = i
cur_blkno = blknos[i]

if cur_blkno not in group_dict:
group_order.append(cur_blkno)
group_dict[cur_blkno] = [(start, n)]
else:
group_dict[cur_blkno].append((start, n))
group_dict[cur_blkno].append((start, n))

for blkno in group_order:
slices = group_dict[blkno]
for blkno, slices in group_dict.items():
if len(slices) == 1:
yield blkno, slice(slices[0][0], slices[0][1])
else:
Expand Down

0 comments on commit 41322cf

Please sign in to comment.