Skip to content

Commit 01c5918

Browse files
WillAydParallels
authored andcommitted
Simplified get_blkno_indexers (pandas-dev#32645)
Co-authored-by: Parallels <[email protected]>
1 parent 79d6ff0 commit 01c5918

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

pandas/_libs/internals.pyx

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import cython
2+
from collections import defaultdict
23
from cython import Py_ssize_t
34

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

375376
object blkno
376-
list group_order
377-
dict group_dict
377+
object group_dict = defaultdict(list)
378378
int64_t[:] res_view
379379

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

396396
yield cur_blkno, slice(start, n)
397397
else:
398-
group_order = []
399-
group_dict = {}
400-
401398
for i in range(1, n):
402399
if blknos[i] != cur_blkno:
403-
if cur_blkno not in group_dict:
404-
group_order.append(cur_blkno)
405-
group_dict[cur_blkno] = [(start, i)]
406-
else:
407-
group_dict[cur_blkno].append((start, i))
400+
group_dict[cur_blkno].append((start, i))
408401

409402
start = i
410403
cur_blkno = blknos[i]
411404

412-
if cur_blkno not in group_dict:
413-
group_order.append(cur_blkno)
414-
group_dict[cur_blkno] = [(start, n)]
415-
else:
416-
group_dict[cur_blkno].append((start, n))
405+
group_dict[cur_blkno].append((start, n))
417406

418-
for blkno in group_order:
419-
slices = group_dict[blkno]
407+
for blkno, slices in group_dict.items():
420408
if len(slices) == 1:
421409
yield blkno, slice(slices[0][0], slices[0][1])
422410
else:

0 commit comments

Comments
 (0)