Skip to content

Commit 8652c35

Browse files
jbrockmendelproost
authored andcommitted
REF: avoid getattr pattern for unstack, assorted cleanups (pandas-dev#29121)
1 parent 369c0e2 commit 8652c35

File tree

7 files changed

+14
-37
lines changed

7 files changed

+14
-37
lines changed

pandas/_libs/algos_take_helper.pxi.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ def get_dispatch(dtypes):
146146
inner_take_2d_axis0 = inner_take_2d_axis0_template % args
147147
inner_take_2d_axis1 = inner_take_2d_axis1_template % args
148148

149-
yield (name, dest, c_type_in, c_type_out, preval, postval, can_copy,
149+
yield (name, dest, c_type_in, c_type_out, preval, postval,
150150
inner_take_1d, inner_take_2d_axis0, inner_take_2d_axis1)
151151

152152
}}
153153

154154

155-
{{for name, dest, c_type_in, c_type_out, preval, postval, can_copy,
155+
{{for name, dest, c_type_in, c_type_out, preval, postval,
156156
inner_take_1d, inner_take_2d_axis0, inner_take_2d_axis1
157157
in get_dispatch(dtypes)}}
158158

pandas/_libs/internals.pyx

+1-4
Original file line numberDiff line numberDiff line change
@@ -441,24 +441,21 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True):
441441
yield blkno, result
442442

443443

444-
def get_blkno_placements(blknos, blk_count, group=True):
444+
def get_blkno_placements(blknos, group=True):
445445
"""
446446
447447
Parameters
448448
----------
449449
blknos : array of int64
450-
blk_count : int
451450
group : bool
452451
453452
Returns
454453
-------
455454
iterator
456455
yield (BlockPlacement, blkno)
457-
458456
"""
459457

460458
blknos = ensure_int64(blknos)
461459

462-
# FIXME: blk_count is unused, but it may avoid the use of dicts in cython
463460
for blkno, indexer in get_blkno_indexers(blknos, group):
464461
yield blkno, BlockPlacement(indexer)

pandas/_libs/intervaltree.pxi.in

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ cdef class IntervalTree(IntervalMixin):
2525

2626
we are emulating the IndexEngine interface
2727
"""
28-
cdef:
29-
readonly object left, right, root, dtype
30-
readonly str closed
28+
cdef readonly:
29+
object left, right, root, dtype
30+
str closed
3131
object _is_overlapping, _left_sorter, _right_sorter
3232

3333
def __init__(self, left, right, closed='right', leaf_size=100):
@@ -259,14 +259,14 @@ cdef class {{dtype_title}}Closed{{closed_title}}IntervalNode:
259259
Categorizes intervals by those that fall to the left, those that fall to
260260
the right, and those that overlap with the pivot.
261261
"""
262-
cdef:
262+
cdef readonly:
263263
{{dtype_title}}Closed{{closed_title}}IntervalNode left_node, right_node
264264
{{dtype}}_t[:] center_left_values, center_right_values, left, right
265265
int64_t[:] center_left_indices, center_right_indices, indices
266266
{{dtype}}_t min_left, max_right
267-
readonly {{dtype}}_t pivot
268-
readonly int64_t n_elements, n_center, leaf_size
269-
readonly bint is_leaf_node
267+
{{dtype}}_t pivot
268+
int64_t n_elements, n_center, leaf_size
269+
bint is_leaf_node
270270

271271
def __init__(self,
272272
ndarray[{{dtype}}_t, ndim=1] left,

pandas/_libs/reshape.pyx

-13
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,6 @@ def unstack(reshape_t[:, :] values, uint8_t[:] mask,
8383
nulls += 1
8484

8585

86-
unstack_uint8 = unstack["uint8_t"]
87-
unstack_uint16 = unstack["uint16_t"]
88-
unstack_uint32 = unstack["uint32_t"]
89-
unstack_uint64 = unstack["uint64_t"]
90-
unstack_int8 = unstack["int8_t"]
91-
unstack_int16 = unstack["int16_t"]
92-
unstack_int32 = unstack["int32_t"]
93-
unstack_int64 = unstack["int64_t"]
94-
unstack_float32 = unstack["float32_t"]
95-
unstack_float64 = unstack["float64_t"]
96-
unstack_object = unstack["object"]
97-
98-
9986
@cython.wraparound(False)
10087
@cython.boundscheck(False)
10188
def explode(ndarray[object] values):

pandas/core/internals/concat.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ def get_mgr_concatenation_plan(mgr, indexers):
6161
blklocs = mgr._blklocs
6262

6363
plan = []
64-
for blkno, placements in libinternals.get_blkno_placements(
65-
blknos, mgr.nblocks, group=False
66-
):
64+
for blkno, placements in libinternals.get_blkno_placements(blknos, group=False):
6765

6866
assert placements.is_slice_like
6967

pandas/core/internals/managers.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1079,9 +1079,7 @@ def value_getitem(placement):
10791079
unfit_mgr_locs = []
10801080
unfit_val_locs = []
10811081
removed_blknos = []
1082-
for blkno, val_locs in libinternals.get_blkno_placements(
1083-
blknos, self.nblocks, group=True
1084-
):
1082+
for blkno, val_locs in libinternals.get_blkno_placements(blknos, group=True):
10851083
blk = self.blocks[blkno]
10861084
blk_locs = blklocs[val_locs.indexer]
10871085
if blk.should_store(value):
@@ -1323,9 +1321,7 @@ def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None):
13231321
# FIXME: mgr_groupby_blknos must return mgr_locs in ascending order,
13241322
# pytables serialization will break otherwise.
13251323
blocks = []
1326-
for blkno, mgr_locs in libinternals.get_blkno_placements(
1327-
blknos, self.nblocks, group=True
1328-
):
1324+
for blkno, mgr_locs in libinternals.get_blkno_placements(blknos, group=True):
13291325
if blkno == -1:
13301326
# If we've got here, fill_tuple was not None.
13311327
fill_value = fill_tuple[0]

pandas/core/reshape/reshape.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ def get_new_values(self):
239239
sorted_values = sorted_values.astype(name, copy=False)
240240

241241
# fill in our values & mask
242-
f = getattr(libreshape, "unstack_{name}".format(name=name))
243-
f(
242+
libreshape.unstack(
244243
sorted_values,
245244
mask.view("u1"),
246245
stride,

0 commit comments

Comments
 (0)