Skip to content

PERF: Using Numpy C-API arange #32681

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 14, 2020
Merged
Changes from 2 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
8 changes: 6 additions & 2 deletions pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ cdef extern from "Python.h":
Py_ssize_t PY_SSIZE_T_MAX

import numpy as np
from numpy cimport int64_t
cimport numpy as cnp
from numpy cimport NPY_INT64, int64_t
cnp.import_array()

from pandas._libs.algos import ensure_int64

Expand Down Expand Up @@ -105,7 +107,9 @@ cdef class BlockPlacement:
Py_ssize_t start, stop, end, _
if not self._has_array:
start, stop, step, _ = slice_get_indices_ex(self._as_slice)
self._as_array = np.arange(start, stop, step, dtype=np.int64)
# NOTE: this is the C-optimized equivalent of
# np.arange(start, stop, step, dtype=np.int64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: i like to add an extra space at the beginning of multi-line comments specifically to avoid confusing this for commented-out code. quotation marks or backticks or ... are also good

self._as_array = cnp.PyArray_Arange(start, stop, step, NPY_INT64)
self._has_array = True
return self._as_array

Expand Down