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

TST: test UInt64Index in tests/indexes/interval/test_constructors.py #49786

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 36 additions & 4 deletions pandas/tests/indexes/interval/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
timedelta_range,
)
import pandas._testing as tm
from pandas.api.types import is_unsigned_integer_dtype
from pandas.core.api import (
Float64Index,
Int64Index,
UInt64Index,
)
from pandas.core.arrays import IntervalArray
import pandas.core.common as com
Expand All @@ -38,25 +40,41 @@ class ConstructorTests:
get_kwargs_from_breaks to the expected format.
"""

def _skip_test_constructor(self, dtype):
# get_kwargs_from_breaks in TestFromTuples and TestClassconstructors just return
# tuples of ints, so IntervalIndex can't know the original dtype
Copy link
Member

Choose a reason for hiding this comment

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

Is the tuple of ints key for the constructor tests or can they be cast to an array where the dtype is known?

return False, ""

@pytest.mark.parametrize(
"breaks",
[
[3, 14, 15, 92, 653],
np.arange(10, dtype="int64"),
Int64Index(range(-10, 11)),
UInt64Index(range(10, 31)),
Float64Index(np.arange(20, 30, 0.5)),
date_range("20180101", periods=10),
date_range("20180101", periods=10, tz="US/Eastern"),
timedelta_range("1 day", periods=10),
],
)
def test_constructor(self, constructor, breaks, closed, name):
@pytest.mark.parametrize("use_dtype", [True, False])
def test_constructor(self, constructor, breaks, closed, name, use_dtype):
breaks_dtype = getattr(breaks, "dtype", "int64")

skip, skip_msg = self._skip_test_constructor(breaks_dtype)
if skip:
pytest.skip(skip_msg)

result_kwargs = self.get_kwargs_from_breaks(breaks, closed)
if use_dtype:
result_kwargs["dtype"] = IntervalDtype(breaks_dtype, closed=closed)

result = constructor(closed=closed, name=name, **result_kwargs)

assert result.closed == closed
assert result.name == name
assert result.dtype.subtype == getattr(breaks, "dtype", "int64")
assert result.dtype.subtype == breaks_dtype
tm.assert_index_equal(result.left, Index(breaks[:-1]))
tm.assert_index_equal(result.right, Index(breaks[1:]))

Expand Down Expand Up @@ -86,8 +104,7 @@ def test_constructor_dtype(self, constructor, breaks, subtype):
"breaks",
[
Int64Index([0, 1, 2, 3, 4]),
Int64Index([0, 1, 2, 3, 4]),
Int64Index([0, 1, 2, 3, 4]),
UInt64Index([0, 1, 2, 3, 4]),
Float64Index([0, 1, 2, 3, 4]),
date_range("2017-01-01", periods=5),
timedelta_range("1 day", periods=5),
Expand Down Expand Up @@ -123,6 +140,7 @@ def test_constructor_nan(self, constructor, breaks, closed):
[
[],
np.array([], dtype="int64"),
np.array([], dtype="uint64"),
np.array([], dtype="float64"),
np.array([], dtype="datetime64[ns]"),
np.array([], dtype="timedelta64[ns]"),
Expand Down Expand Up @@ -294,6 +312,12 @@ def test_left_right_dont_share_data(self):
class TestFromTuples(ConstructorTests):
"""Tests specific to IntervalIndex.from_tuples"""

def _skip_test_constructor(self, dtype):
if is_unsigned_integer_dtype(dtype):
return True, "tuples don't have a dtype"
else:
return False, ""

@pytest.fixture
def constructor(self):
return IntervalIndex.from_tuples
Expand Down Expand Up @@ -341,6 +365,14 @@ def test_na_tuples(self):
class TestClassConstructors(ConstructorTests):
"""Tests specific to the IntervalIndex/Index constructors"""

def _skip_test_constructor(self, dtype):
# get_kwargs_from_breaks in TestFromTuples and TestClassconstructors just return
# tuples of ints, so IntervalIndex can't know the original dtype
if is_unsigned_integer_dtype(dtype):
return True, "tuples don't have a dtype"
else:
return False, ""

@pytest.fixture(
params=[IntervalIndex, partial(Index, dtype="interval")],
ids=["IntervalIndex", "Index"],
Expand Down