Skip to content

Commit 5568230

Browse files
committed
MAINT: Add integer dtype fixtures to conftest.py
1 parent cce26b5 commit 5568230

File tree

3 files changed

+67
-16
lines changed

3 files changed

+67
-16
lines changed

pandas/conftest.py

+63
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,66 @@ def string_dtype(request):
170170
* 'U'
171171
"""
172172
return request.param
173+
174+
175+
@pytest.fixture(params=["float32", "float64"])
176+
def float_dtype(request):
177+
"""
178+
Parameterized fixture for float dtypes.
179+
180+
* float32
181+
* float64
182+
"""
183+
184+
return request.param
185+
186+
187+
UNSIGNED_INT_DTYPES = ["uint8", "uint16", "uint32", "uint64"]
188+
SIGNED_INT_DTYPES = ["int8", "int16", "int32", "int64"]
189+
ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES
190+
191+
192+
@pytest.fixture(params=SIGNED_INT_DTYPES)
193+
def sint_dtype(request):
194+
"""
195+
Parameterized fixture for signed integer dtypes.
196+
197+
* int8
198+
* int16
199+
* int32
200+
* int64
201+
"""
202+
203+
return request.param
204+
205+
206+
@pytest.fixture(params=UNSIGNED_INT_DTYPES)
207+
def uint_dtype(request):
208+
"""
209+
Parameterized fixture for unsigned integer dtypes.
210+
211+
* uint8
212+
* uint16
213+
* uint32
214+
* uint64
215+
"""
216+
217+
return request.param
218+
219+
220+
@pytest.fixture(params=ALL_INT_DTYPES)
221+
def any_int_dtype(request):
222+
"""
223+
Parameterized fixture for any integer dtypes.
224+
225+
* int8
226+
* uint8
227+
* int16
228+
* uint16
229+
* int32
230+
* uint32
231+
* int64
232+
* uint64
233+
"""
234+
235+
return request.param

pandas/tests/indexes/test_numeric.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -451,16 +451,12 @@ def test_astype(self):
451451
i = Float64Index([0, 1.1, np.NAN])
452452
pytest.raises(ValueError, lambda: i.astype(dtype))
453453

454-
@pytest.mark.parametrize("int_dtype", ["uint8", "uint16", "uint32",
455-
"uint64", "int32", "int64",
456-
"int16", "int8"])
457-
@pytest.mark.parametrize("float_dtype", ["float16", "float32", "float64"])
458-
def test_type_coercion(self, int_dtype, float_dtype):
454+
def test_type_coercion(self, any_int_dtype, float_dtype):
459455

460456
# see gh-15832
461457
msg = "Trying to coerce float values to integers"
462458
with tm.assert_raises_regex(ValueError, msg):
463-
Index([1, 2, 3.5], dtype=int_dtype)
459+
Index([1, 2, 3.5], dtype=any_int_dtype)
464460

465461
i = Index([1, 2, 3.5], dtype=float_dtype)
466462
tm.assert_index_equal(i, Index([1, 2, 3.5]))
@@ -876,8 +872,6 @@ def test_constructor_corner(self):
876872
with tm.assert_raises_regex(TypeError, 'casting'):
877873
Int64Index(arr_with_floats)
878874

879-
@pytest.mark.parametrize("uint_dtype", ["uint8", "uint16",
880-
"uint32", "uint64"])
881875
def test_constructor_coercion_signed_to_unsigned(self, uint_dtype):
882876

883877
# see gh-15832

pandas/tests/series/test_constructors.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -546,23 +546,17 @@ def test_constructor_cast(self):
546546
with tm.assert_raises_regex(ValueError, msg):
547547
Series(["a", "b", "c"], dtype=float)
548548

549-
@pytest.mark.parametrize("uint_dtype", ["uint8", "uint16",
550-
"uint32", "uint64"])
551549
def test_constructor_unsigned_dtype_overflow(self, uint_dtype):
552550
# see gh-15832
553551
msg = 'Trying to coerce negative values to unsigned integers'
554552
with tm.assert_raises_regex(OverflowError, msg):
555553
Series([-1], dtype=uint_dtype)
556554

557-
@pytest.mark.parametrize("int_dtype", ["uint8", "uint16", "uint32",
558-
"uint64", "int32", "int64",
559-
"int16", "int8"])
560-
@pytest.mark.parametrize("float_dtype", ["float16", "float32", "float64"])
561-
def test_constructor_coerce_float_fail(self, int_dtype, float_dtype):
555+
def test_constructor_coerce_float_fail(self, any_int_dtype, float_dtype):
562556
# see gh-15832
563557
msg = "Trying to coerce float values to integers"
564558
with tm.assert_raises_regex(ValueError, msg):
565-
Series([1, 2, 3.5], dtype=int_dtype)
559+
Series([1, 2, 3.5], dtype=any_int_dtype)
566560

567561
s = Series([1, 2, 3.5], dtype=float_dtype)
568562
expected = Series([1, 2, 3.5]).astype(float_dtype)

0 commit comments

Comments
 (0)