Skip to content

REF: avoid getattr pattern for unstack, assorted cleanups #29121

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 4 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions pandas/_libs/algos_take_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ def get_dispatch(dtypes):
inner_take_2d_axis0 = inner_take_2d_axis0_template % args
inner_take_2d_axis1 = inner_take_2d_axis1_template % args

yield (name, dest, c_type_in, c_type_out, preval, postval, can_copy,
yield (name, dest, c_type_in, c_type_out, preval, postval,
inner_take_1d, inner_take_2d_axis0, inner_take_2d_axis1)

}}


{{for name, dest, c_type_in, c_type_out, preval, postval, can_copy,
{{for name, dest, c_type_in, c_type_out, preval, postval,
inner_take_1d, inner_take_2d_axis0, inner_take_2d_axis1
in get_dispatch(dtypes)}}

Expand Down
5 changes: 1 addition & 4 deletions pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -441,24 +441,21 @@ def get_blkno_indexers(int64_t[:] blknos, bint group=True):
yield blkno, result


def get_blkno_placements(blknos, blk_count, group=True):
def get_blkno_placements(blknos, group=True):
"""

Parameters
----------
blknos : array of int64
blk_count : int
group : bool

Returns
-------
iterator
yield (BlockPlacement, blkno)

"""

blknos = ensure_int64(blknos)

# FIXME: blk_count is unused, but it may avoid the use of dicts in cython
for blkno, indexer in get_blkno_indexers(blknos, group):
yield blkno, BlockPlacement(indexer)
14 changes: 7 additions & 7 deletions pandas/_libs/intervaltree.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ cdef class IntervalTree(IntervalMixin):

we are emulating the IndexEngine interface
"""
cdef:
readonly object left, right, root, dtype
readonly str closed
cdef readonly:
object left, right, root, dtype
str closed
object _is_overlapping, _left_sorter, _right_sorter

def __init__(self, left, right, closed='right', leaf_size=100):
Expand Down Expand Up @@ -259,14 +259,14 @@ cdef class {{dtype_title}}Closed{{closed_title}}IntervalNode:
Categorizes intervals by those that fall to the left, those that fall to
the right, and those that overlap with the pivot.
"""
cdef:
cdef readonly:
{{dtype_title}}Closed{{closed_title}}IntervalNode left_node, right_node
{{dtype}}_t[:] center_left_values, center_right_values, left, right
int64_t[:] center_left_indices, center_right_indices, indices
{{dtype}}_t min_left, max_right
readonly {{dtype}}_t pivot
readonly int64_t n_elements, n_center, leaf_size
readonly bint is_leaf_node
{{dtype}}_t pivot
int64_t n_elements, n_center, leaf_size
bint is_leaf_node

def __init__(self,
ndarray[{{dtype}}_t, ndim=1] left,
Expand Down
13 changes: 0 additions & 13 deletions pandas/_libs/reshape.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,6 @@ def unstack(reshape_t[:, :] values, uint8_t[:] mask,
nulls += 1


unstack_uint8 = unstack["uint8_t"]
unstack_uint16 = unstack["uint16_t"]
unstack_uint32 = unstack["uint32_t"]
unstack_uint64 = unstack["uint64_t"]
unstack_int8 = unstack["int8_t"]
unstack_int16 = unstack["int16_t"]
unstack_int32 = unstack["int32_t"]
unstack_int64 = unstack["int64_t"]
unstack_float32 = unstack["float32_t"]
unstack_float64 = unstack["float64_t"]
unstack_object = unstack["object"]


@cython.wraparound(False)
@cython.boundscheck(False)
def explode(ndarray[object] values):
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def get_mgr_concatenation_plan(mgr, indexers):
blklocs = mgr._blklocs

plan = []
for blkno, placements in libinternals.get_blkno_placements(
blknos, mgr.nblocks, group=False
):
for blkno, placements in libinternals.get_blkno_placements(blknos, group=False):

assert placements.is_slice_like

Expand Down
8 changes: 2 additions & 6 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,9 +1079,7 @@ def value_getitem(placement):
unfit_mgr_locs = []
unfit_val_locs = []
removed_blknos = []
for blkno, val_locs in libinternals.get_blkno_placements(
blknos, self.nblocks, group=True
):
for blkno, val_locs in libinternals.get_blkno_placements(blknos, group=True):
blk = self.blocks[blkno]
blk_locs = blklocs[val_locs.indexer]
if blk.should_store(value):
Expand Down Expand Up @@ -1323,9 +1321,7 @@ def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None):
# FIXME: mgr_groupby_blknos must return mgr_locs in ascending order,
# pytables serialization will break otherwise.
blocks = []
for blkno, mgr_locs in libinternals.get_blkno_placements(
blknos, self.nblocks, group=True
):
for blkno, mgr_locs in libinternals.get_blkno_placements(blknos, group=True):
if blkno == -1:
# If we've got here, fill_tuple was not None.
fill_value = fill_tuple[0]
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ def get_new_values(self):
sorted_values = sorted_values.astype(name, copy=False)

# fill in our values & mask
f = getattr(libreshape, "unstack_{name}".format(name=name))
f(
libreshape.unstack(
sorted_values,
mask.view("u1"),
stride,
Expand Down