Skip to content

CLN: Remove int32 and float32 dtypes from IntervalTree #30598

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
Jan 1, 2020
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
5 changes: 1 addition & 4 deletions pandas/_libs/intervaltree.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ from pandas._libs.algos import is_monotonic

ctypedef fused int_scalar_t:
int64_t
int32_t
float64_t
float32_t

ctypedef fused uint_scalar_t:
uint64_t
float64_t
float32_t

ctypedef fused scalar_t:
int_scalar_t
Expand Down Expand Up @@ -212,7 +209,7 @@ cdef sort_values_and_indices(all_values, all_indices, subset):
{{py:

nodes = []
for dtype in ['float32', 'float64', 'int32', 'int64', 'uint64']:
for dtype in ['float64', 'int64', 'uint64']:
for closed, cmp_left, cmp_right in [
('left', '<=', '<'),
('right', '<', '<='),
Expand Down
31 changes: 14 additions & 17 deletions pandas/tests/indexes/interval/test_interval_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def skipif_32bit(param):
return pytest.param(param, marks=marks)


@pytest.fixture(
scope="class", params=["int32", "int64", "float32", "float64", "uint64"]
)
@pytest.fixture(scope="class", params=["int64", "float64", "uint64"])
def dtype(request):
return request.param

Expand All @@ -39,12 +37,9 @@ def leaf_size(request):
@pytest.fixture(
params=[
np.arange(5, dtype="int64"),
np.arange(5, dtype="int32"),
np.arange(5, dtype="uint64"),
np.arange(5, dtype="float64"),
np.arange(5, dtype="float32"),
np.array([0, 1, 2, 3, 4, np.nan], dtype="float64"),
np.array([0, 1, 2, 3, 4, np.nan], dtype="float32"),
]
)
def tree(request, leaf_size):
Expand All @@ -64,13 +59,14 @@ def test_get_indexer(self, tree):
tree.get_indexer(np.array([3.0]))

@pytest.mark.parametrize(
"dtype, target_value", [("int64", 2 ** 63 + 1), ("uint64", -1)]
"dtype, target_value, target_dtype",
[("int64", 2 ** 63 + 1, "uint64"), ("uint64", -1, "int64")],
)
def test_get_indexer_overflow(self, dtype, target_value):
def test_get_indexer_overflow(self, dtype, target_value, target_dtype):
left, right = np.array([0, 1], dtype=dtype), np.array([1, 2], dtype=dtype)
tree = IntervalTree(left, right)

result = tree.get_indexer(np.array([target_value]))
result = tree.get_indexer(np.array([target_value], dtype=target_dtype))
expected = np.array([-1], dtype="intp")
tm.assert_numpy_array_equal(result, expected)

Expand All @@ -94,12 +90,13 @@ def test_get_indexer_non_unique(self, tree):
tm.assert_numpy_array_equal(result, expected)

@pytest.mark.parametrize(
"dtype, target_value", [("int64", 2 ** 63 + 1), ("uint64", -1)]
"dtype, target_value, target_dtype",
[("int64", 2 ** 63 + 1, "uint64"), ("uint64", -1, "int64")],
)
def test_get_indexer_non_unique_overflow(self, dtype, target_value):
def test_get_indexer_non_unique_overflow(self, dtype, target_value, target_dtype):
left, right = np.array([0, 2], dtype=dtype), np.array([1, 3], dtype=dtype)
tree = IntervalTree(left, right)
target = np.array([target_value])
target = np.array([target_value], dtype=target_dtype)

result_indexer, result_missing = tree.get_indexer_non_unique(target)
expected_indexer = np.array([-1], dtype="intp")
Expand Down Expand Up @@ -146,10 +143,10 @@ def test_get_indexer_closed(self, closed, leaf_size):
@pytest.mark.parametrize(
"left, right, expected",
[
(np.array([0, 1, 4]), np.array([2, 3, 5]), True),
(np.array([0, 1, 2]), np.array([5, 4, 3]), True),
(np.array([0, 1, 4], dtype="int64"), np.array([2, 3, 5]), True),
(np.array([0, 1, 2], dtype="int64"), np.array([5, 4, 3]), True),
(np.array([0, 1, np.nan]), np.array([5, 4, np.nan]), True),
(np.array([0, 2, 4]), np.array([1, 3, 5]), False),
(np.array([0, 2, 4], dtype="int64"), np.array([1, 3, 5]), False),
(np.array([0, 2, np.nan]), np.array([1, 3, np.nan]), False),
],
)
Expand All @@ -164,7 +161,7 @@ def test_is_overlapping(self, closed, order, left, right, expected):
def test_is_overlapping_endpoints(self, closed, order):
"""shared endpoints are marked as overlapping"""
# GH 23309
left, right = np.arange(3), np.arange(1, 4)
left, right = np.arange(3, dtype="int64"), np.arange(1, 4)
tree = IntervalTree(left[order], right[order], closed=closed)
result = tree.is_overlapping
expected = closed == "both"
Expand All @@ -187,7 +184,7 @@ def test_is_overlapping_trivial(self, closed, left, right):
@pytest.mark.skipif(compat.is_platform_32bit(), reason="GH 23440")
def test_construction_overflow(self):
# GH 25485
left, right = np.arange(101), [np.iinfo(np.int64).max] * 101
left, right = np.arange(101, dtype="int64"), [np.iinfo(np.int64).max] * 101
tree = IntervalTree(left, right)

# pivot should be average of left/right medians
Expand Down