Skip to content
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

BUG: IntervalIndex.get_indexer raising for read only array #53703

Merged
merged 3 commits into from
Jun 19, 2023
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ Strings

Interval
^^^^^^^^
-
- :meth:`pd.IntervalIndex.get_indexer` and :meth:`pd.IntervalIndex.get_indexer_nonunique` raising if ``target`` is read-only array (:issue:`53703`)
-

Indexing
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/intervaltree.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ cdef class IntervalTree(IntervalMixin):
sort_order = self.left_sorter
return is_monotonic(sort_order, False)[0]

def get_indexer(self, scalar_t[:] target) -> np.ndarray:
def get_indexer(self, ndarray[scalar_t, ndim=1] target) -> np.ndarray:
"""Return the positions corresponding to unique intervals that overlap
with the given array of scalar targets.
"""
Expand Down Expand Up @@ -153,7 +153,7 @@ cdef class IntervalTree(IntervalMixin):
old_len = result.data.n
return result.to_array().astype('intp')

def get_indexer_non_unique(self, scalar_t[:] target):
def get_indexer_non_unique(self, ndarray[scalar_t, ndim=1] target):
"""Return the positions corresponding to intervals that overlap with
the given array of scalar targets. Non-unique positions are repeated.
"""
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/indexes/interval/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@ def test_get_indexer_interval_index(self, box):
expected = np.array([-1, -1, -1], dtype=np.intp)
tm.assert_numpy_array_equal(actual, expected)

def test_get_indexer_read_only(self):
idx = interval_range(start=0, end=5)
arr = np.array([1, 2])
arr.flags.writeable = False
result = idx.get_indexer(arr)
expected = np.array([0, 1])
tm.assert_numpy_array_equal(result, expected, check_dtype=False)

result = idx.get_indexer_non_unique(arr)[0]
tm.assert_numpy_array_equal(result, expected, check_dtype=False)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm what's going on with the dtype? Wouldn't expect that issue

Copy link
Member Author

Choose a reason for hiding this comment

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

Windows/non windows stuff and since the dtype really doesnt matter here, I just ignored it

Copy link
Member

Choose a reason for hiding this comment

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

Maybe you can explicitly specify the type of the np.array call instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

This would kill the 32 bit build... Open for suggestions but dtype really doesn't matter



class TestSliceLocs:
def test_slice_locs_with_interval(self):
Expand Down