Skip to content

Commit 0104391

Browse files
Terji PetersenTerji Petersen
authored andcommitted
make tests fixtures-based
1 parent 2153c84 commit 0104391

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ repos:
5959
- flake8==5.0.4
6060
- flake8-bugbear==22.7.1
6161
- pandas-dev-flaker==0.5.0
62-
- repo: https://github.com/pycqa/pylint
63-
rev: v2.15.5
64-
hooks:
65-
- id: pylint
66-
stages: [manual]
6762
- repo: https://github.com/PyCQA/isort
6863
rev: 5.10.1
6964
hooks:

pandas/tests/indexes/interval/test_constructors.py

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,43 +40,36 @@ class ConstructorTests:
4040
get_kwargs_from_breaks to the expected format.
4141
"""
4242

43-
def _skip_test_constructor(self, dtype):
44-
# get_kwargs_from_breaks in TestFromTuples and TestClassconstructors just return
45-
# tuples of ints, so IntervalIndex can't know the original dtype
46-
return False, ""
47-
48-
@pytest.mark.parametrize(
49-
"breaks",
50-
[
51-
[3, 14, 15, 92, 653],
52-
np.arange(10, dtype="int64"),
53-
Int64Index(range(-10, 11)),
54-
UInt64Index(range(10, 31)),
55-
Float64Index(np.arange(20, 30, 0.5)),
56-
date_range("20180101", periods=10),
57-
date_range("20180101", periods=10, tz="US/Eastern"),
58-
timedelta_range("1 day", periods=10),
59-
],
43+
@pytest.fixture(
44+
params=[
45+
([3, 14, 15, 92, 653], np.int64),
46+
(np.arange(10, dtype="int64"), np.int64),
47+
(Int64Index(range(-10, 11)), np.int64),
48+
(UInt64Index(range(10, 31)), np.uint64),
49+
(Float64Index(np.arange(20, 30, 0.5)), np.float64),
50+
(date_range("20180101", periods=10), "<M8[ns]"),
51+
(
52+
date_range("20180101", periods=10, tz="US/Eastern"),
53+
"datetime64[ns, US/Eastern]",
54+
),
55+
(timedelta_range("1 day", periods=10), "<m8[ns]"),
56+
]
6057
)
61-
@pytest.mark.parametrize("use_dtype", [True, False])
62-
def test_constructor(self, constructor, breaks, closed, name, use_dtype):
63-
breaks_dtype = getattr(breaks, "dtype", "int64")
58+
def breaks_and_expected_subtype(self, request):
59+
return request.param
6460

65-
skip, skip_msg = self._skip_test_constructor(breaks_dtype)
66-
if skip:
67-
pytest.skip(skip_msg)
61+
def test_constructor(self, constructor, breaks_and_expected_subtype, closed, name):
62+
breaks, expected_subtype = breaks_and_expected_subtype
6863

6964
result_kwargs = self.get_kwargs_from_breaks(breaks, closed)
70-
if use_dtype:
71-
result_kwargs["dtype"] = IntervalDtype(breaks_dtype, closed=closed)
7265

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

7568
assert result.closed == closed
7669
assert result.name == name
77-
assert result.dtype.subtype == breaks_dtype
78-
tm.assert_index_equal(result.left, Index(breaks[:-1]))
79-
tm.assert_index_equal(result.right, Index(breaks[1:]))
70+
assert result.dtype.subtype == expected_subtype
71+
tm.assert_index_equal(result.left, Index(breaks[:-1], dtype=expected_subtype))
72+
tm.assert_index_equal(result.right, Index(breaks[1:], dtype=expected_subtype))
8073

8174
@pytest.mark.parametrize(
8275
"breaks, subtype",
@@ -309,7 +302,27 @@ def test_left_right_dont_share_data(self):
309302
assert result._left.base is None or result._left.base is not result._right.base
310303

311304

312-
class TestFromTuples(ConstructorTests):
305+
class TuplesClassConstructorTests(ConstructorTests):
306+
@pytest.fixture(
307+
params=[
308+
([3, 14, 15, 92, 653], np.int64),
309+
(np.arange(10, dtype="int64"), np.int64),
310+
(Int64Index(range(-10, 11)), np.int64),
311+
(UInt64Index(range(10, 31)), np.int64),
312+
(Float64Index(np.arange(20, 30, 0.5)), np.float64),
313+
(date_range("20180101", periods=10), "<M8[ns]"),
314+
(
315+
date_range("20180101", periods=10, tz="US/Eastern"),
316+
"datetime64[ns, US/Eastern]",
317+
),
318+
(timedelta_range("1 day", periods=10), "<m8[ns]"),
319+
]
320+
)
321+
def breaks_and_expected_subtype(self, request):
322+
return request.param
323+
324+
325+
class TestFromTuples(TuplesClassConstructorTests):
313326
"""Tests specific to IntervalIndex.from_tuples"""
314327

315328
def _skip_test_constructor(self, dtype):
@@ -362,7 +375,7 @@ def test_na_tuples(self):
362375
tm.assert_index_equal(idx_na_tuple, idx_na_element)
363376

364377

365-
class TestClassConstructors(ConstructorTests):
378+
class TestClassConstructors(TuplesClassConstructorTests):
366379
"""Tests specific to the IntervalIndex/Index constructors"""
367380

368381
def _skip_test_constructor(self, dtype):

0 commit comments

Comments
 (0)