Skip to content

Simplified get_blkno_indexers #32645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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