Skip to content

Commit

Permalink
Merge branch 'take'
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed May 8, 2015
2 parents c9bf162 + ca55818 commit be2a9f8
Show file tree
Hide file tree
Showing 5 changed files with 2,125 additions and 307 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.16.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Bug Fixes
- Bug where ``TimdeltaIndex`` were not properly serialized in fixed ``HDFStore`` (:issue:`9635`)
- Bug with ``TimedeltaIndex`` constructor ignoring ``name`` when given another ``TimedeltaIndex`` as data (:issue:`10025`).
- Bug in ``DataFrameFormatter._get_formatted_index`` with not applying ``max_colwidth`` to the ``DataFrame`` index (:issue:`7856`)

- Bug in ``.loc`` with a read-only ndarray data source (:issue:`10043`)
- Bug in ``groupby.apply()`` that would raise if a passed user defined function either returned only ``None`` (for all input). (:issue:`9685`)

- Bug in plotting continuously using ``secondary_y`` may not show legend properly. (:issue:`9610`, :issue:`9779`)
Expand Down
62 changes: 53 additions & 9 deletions pandas/src/generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ def take_1d_%(name)s_%(dest)s(ndarray[%(c_type_in)s] values,
"""

take_2d_axis0_template = """@cython.wraparound(False)
@cython.boundscheck(False)
def take_2d_axis0_%(name)s_%(dest)s(%(c_type_in)s[:, :] values,
ndarray[int64_t] indexer,
%(c_type_out)s[:, :] out,
fill_value=np.nan):
inner_take_2d_axis0_template = """\
cdef:
Py_ssize_t i, j, k, n, idx
%(c_type_out)s fv
Expand Down Expand Up @@ -140,12 +135,34 @@ def take_2d_axis0_%(name)s_%(dest)s(%(c_type_in)s[:, :] values,
"""

take_2d_axis1_template = """@cython.wraparound(False)
take_2d_axis0_template = """\
@cython.wraparound(False)
@cython.boundscheck(False)
def take_2d_axis1_%(name)s_%(dest)s(%(c_type_in)s[:, :] values,
cdef inline take_2d_axis0_%(name)s_%(dest)s_memview(%(c_type_in)s[:, :] values,
int64_t[:] indexer,
%(c_type_out)s[:, :] out,
fill_value=np.nan):
""" + inner_take_2d_axis0_template + """
@cython.wraparound(False)
@cython.boundscheck(False)
def take_2d_axis0_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
ndarray[int64_t] indexer,
%(c_type_out)s[:, :] out,
fill_value=np.nan):
if values.flags.writeable:
# We can call the memoryview version of the code
take_2d_axis0_%(name)s_%(dest)s_memview(values, indexer, out,
fill_value=fill_value)
return
# We cannot use the memoryview version on readonly-buffers due to
# a limitation of Cython's typed memoryviews. Instead we can use
# the slightly slower Cython ndarray type directly.
""" + inner_take_2d_axis0_template


inner_take_2d_axis1_template = """\
cdef:
Py_ssize_t i, j, k, n, idx
%(c_type_out)s fv
Expand All @@ -165,9 +182,36 @@ def take_2d_axis1_%(name)s_%(dest)s(%(c_type_in)s[:, :] values,
out[i, j] = fv
else:
out[i, j] = %(preval)svalues[i, idx]%(postval)s
"""

take_2d_axis1_template = """\
@cython.wraparound(False)
@cython.boundscheck(False)
cdef inline take_2d_axis1_%(name)s_%(dest)s_memview(%(c_type_in)s[:, :] values,
int64_t[:] indexer,
%(c_type_out)s[:, :] out,
fill_value=np.nan):
""" + inner_take_2d_axis1_template + """
@cython.wraparound(False)
@cython.boundscheck(False)
def take_2d_axis1_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
ndarray[int64_t] indexer,
%(c_type_out)s[:, :] out,
fill_value=np.nan):
if values.flags.writeable:
# We can call the memoryview version of the code
take_2d_axis1_%(name)s_%(dest)s_memview(values, indexer, out,
fill_value=fill_value)
return
# We cannot use the memoryview version on readonly-buffers due to
# a limitation of Cython's typed memoryviews. Instead we can use
# the slightly slower Cython ndarray type directly.
""" + inner_take_2d_axis1_template


take_2d_multi_template = """@cython.wraparound(False)
@cython.boundscheck(False)
def take_2d_multi_%(name)s_%(dest)s(ndarray[%(c_type_in)s, ndim=2] values,
Expand Down
Loading

0 comments on commit be2a9f8

Please sign in to comment.