Skip to content

Commit

Permalink
make skip options more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
Terji Petersen authored and Terji Petersen committed Nov 20, 2022
1 parent cf296fd commit 2153c84
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions pandas/tests/indexes/interval/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ class ConstructorTests:
get_kwargs_from_breaks to the expected format.
"""

# get_kwargs_from_breaks in TestFromTuples and TestClassconstructors just return
# tuples of ints, so IntervalIndex can't know the original dtype was uint
_use_dtype_in_test_constructor_uint = False
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
return False, ""

@pytest.mark.parametrize(
"breaks",
Expand All @@ -60,9 +61,13 @@ class ConstructorTests:
@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)
is_uint = is_unsigned_integer_dtype(breaks_dtype)
if use_dtype or (self._use_dtype_in_test_constructor_uint and is_uint):
if use_dtype:
result_kwargs["dtype"] = IntervalDtype(breaks_dtype, closed=closed)

result = constructor(closed=closed, name=name, **result_kwargs)
Expand Down Expand Up @@ -307,7 +312,11 @@ def test_left_right_dont_share_data(self):
class TestFromTuples(ConstructorTests):
"""Tests specific to IntervalIndex.from_tuples"""

_use_dtype_in_test_constructor_uint = True
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):
Expand Down Expand Up @@ -356,7 +365,13 @@ def test_na_tuples(self):
class TestClassConstructors(ConstructorTests):
"""Tests specific to the IntervalIndex/Index constructors"""

_use_dtype_in_test_constructor_uint = True
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")],
Expand Down

0 comments on commit 2153c84

Please sign in to comment.