Skip to content

CLN: some code cleanups #32177

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 7 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions pandas/_libs/hashtable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ cdef class Factorizer:
self, ndarray[object] values, sort=False, na_sentinel=-1, na_value=None
):
"""
Examples
--------
Factorize values with nans replaced by na_sentinel

>>> factorize(np.array([1,2,np.nan], dtype='O'), na_sentinel=20)
array([ 0, 1, 20])
"""
Expand Down Expand Up @@ -131,7 +134,10 @@ cdef class Int64Factorizer:
def factorize(self, const int64_t[:] values, sort=False,
na_sentinel=-1, na_value=None):
"""
Examples
--------
Factorize values with nans replaced by na_sentinel

>>> factorize(np.array([1,2,np.nan], dtype='O'), na_sentinel=20)
array([ 0, 1, 20])
"""
Expand Down
6 changes: 2 additions & 4 deletions pandas/_libs/internals.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ 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)
self._as_array = np.arange(start, stop, step, dtype=np.int64)
self._has_array = True
return self._as_array

Expand Down Expand Up @@ -283,8 +282,7 @@ cdef slice_getitem(slice slc, ind):
s_start, s_stop, s_step, s_len = slice_get_indices_ex(slc)

if isinstance(ind, slice):
ind_start, ind_stop, ind_step, ind_len = slice_get_indices_ex(ind,
s_len)
ind_start, ind_stop, ind_step, ind_len = slice_get_indices_ex(ind, s_len)

if ind_step > 0 and ind_len == s_len:
# short-cut for no-op slice
Expand Down
3 changes: 1 addition & 2 deletions pandas/_libs/interval.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,7 @@ cdef class Interval(IntervalMixin):

@cython.wraparound(False)
@cython.boundscheck(False)
def intervals_to_interval_bounds(ndarray intervals,
bint validate_closed=True):
def intervals_to_interval_bounds(ndarray intervals, bint validate_closed=True):
Copy link
Member

Choose a reason for hiding this comment

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

its worth double-checking me on this, but i think for non-cdef/cpdef functions, using cython syntax for the annotations doesnt help perf. in these cases, let's just use python versions

Copy link
Contributor

Choose a reason for hiding this comment

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

right, but that is orthogonal to this PR

"""
Parameters
----------
Expand Down
28 changes: 16 additions & 12 deletions pandas/_libs/join.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -803,18 +803,22 @@ def asof_join_nearest_on_X_by_Y(asof_t[:] left_values,
right_indexer = np.empty(left_size, dtype=np.int64)

# search both forward and backward
bli, bri = asof_join_backward_on_X_by_Y(left_values,
right_values,
left_by_values,
right_by_values,
allow_exact_matches,
tolerance)
fli, fri = asof_join_forward_on_X_by_Y(left_values,
right_values,
left_by_values,
right_by_values,
allow_exact_matches,
tolerance)
bli, bri = asof_join_backward_on_X_by_Y(
left_values,
right_values,
left_by_values,
right_by_values,
allow_exact_matches,
tolerance,
)
fli, fri = asof_join_forward_on_X_by_Y(
left_values,
right_values,
left_by_values,
right_by_values,
allow_exact_matches,
tolerance,
)

for i in range(len(bri)):
# choose timestamp from right with smaller difference
Expand Down
Loading