Skip to content

Commit 7a058c0

Browse files
SaturnFromTitanCloseChoice
authored andcommitted
TST: Dtype constants into pandas._testing to avoid direct imports from conftest (pandas-dev#33661)
1 parent 90ef74c commit 7a058c0

File tree

5 files changed

+69
-82
lines changed

5 files changed

+69
-82
lines changed

pandas/_testing.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
)
2323

2424
import pandas._libs.testing as _testing
25-
from pandas._typing import FilePathOrBuffer, FrameOrSeries
25+
from pandas._typing import Dtype, FilePathOrBuffer, FrameOrSeries
2626
from pandas.compat import _get_lzma_file, _import_lzma
2727

2828
from pandas.core.dtypes.common import (
@@ -73,6 +73,37 @@
7373
_K = 4
7474
_RAISE_NETWORK_ERROR_DEFAULT = False
7575

76+
UNSIGNED_INT_DTYPES: List[Dtype] = ["uint8", "uint16", "uint32", "uint64"]
77+
UNSIGNED_EA_INT_DTYPES: List[Dtype] = ["UInt8", "UInt16", "UInt32", "UInt64"]
78+
SIGNED_INT_DTYPES: List[Dtype] = [int, "int8", "int16", "int32", "int64"]
79+
SIGNED_EA_INT_DTYPES: List[Dtype] = ["Int8", "Int16", "Int32", "Int64"]
80+
ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES
81+
ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES
82+
83+
FLOAT_DTYPES: List[Dtype] = [float, "float32", "float64"]
84+
COMPLEX_DTYPES: List[Dtype] = [complex, "complex64", "complex128"]
85+
STRING_DTYPES: List[Dtype] = [str, "str", "U"]
86+
87+
DATETIME64_DTYPES: List[Dtype] = ["datetime64[ns]", "M8[ns]"]
88+
TIMEDELTA64_DTYPES: List[Dtype] = ["timedelta64[ns]", "m8[ns]"]
89+
90+
BOOL_DTYPES = [bool, "bool"]
91+
BYTES_DTYPES = [bytes, "bytes"]
92+
OBJECT_DTYPES = [object, "object"]
93+
94+
ALL_REAL_DTYPES = FLOAT_DTYPES + ALL_INT_DTYPES
95+
ALL_NUMPY_DTYPES = (
96+
ALL_REAL_DTYPES
97+
+ COMPLEX_DTYPES
98+
+ STRING_DTYPES
99+
+ DATETIME64_DTYPES
100+
+ TIMEDELTA64_DTYPES
101+
+ BOOL_DTYPES
102+
+ OBJECT_DTYPES
103+
+ BYTES_DTYPES
104+
)
105+
106+
76107
# set testing_mode
77108
_testing_mode_warnings = (DeprecationWarning, ResourceWarning)
78109

pandas/conftest.py

+13-47
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from decimal import Decimal
2424
import operator
2525
import os
26-
from typing import List
2726

2827
from dateutil.tz import tzlocal, tzutc
2928
import hypothesis
@@ -32,7 +31,6 @@
3231
import pytest
3332
from pytz import FixedOffset, utc
3433

35-
from pandas._typing import Dtype
3634
import pandas.util._test_decorators as td
3735

3836
import pandas as pd
@@ -864,39 +862,7 @@ def utc_fixture(request):
864862
# ----------------------------------------------------------------
865863
# Dtypes
866864
# ----------------------------------------------------------------
867-
868-
UNSIGNED_INT_DTYPES = ["uint8", "uint16", "uint32", "uint64"]
869-
UNSIGNED_EA_INT_DTYPES = ["UInt8", "UInt16", "UInt32", "UInt64"]
870-
SIGNED_INT_DTYPES: List[Dtype] = [int, "int8", "int16", "int32", "int64"]
871-
SIGNED_EA_INT_DTYPES = ["Int8", "Int16", "Int32", "Int64"]
872-
ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES
873-
ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES
874-
875-
FLOAT_DTYPES: List[Dtype] = [float, "float32", "float64"]
876-
COMPLEX_DTYPES: List[Dtype] = [complex, "complex64", "complex128"]
877-
STRING_DTYPES: List[Dtype] = [str, "str", "U"]
878-
879-
DATETIME64_DTYPES = ["datetime64[ns]", "M8[ns]"]
880-
TIMEDELTA64_DTYPES = ["timedelta64[ns]", "m8[ns]"]
881-
882-
BOOL_DTYPES = [bool, "bool"]
883-
BYTES_DTYPES = [bytes, "bytes"]
884-
OBJECT_DTYPES = [object, "object"]
885-
886-
ALL_REAL_DTYPES = FLOAT_DTYPES + ALL_INT_DTYPES
887-
ALL_NUMPY_DTYPES = (
888-
ALL_REAL_DTYPES
889-
+ COMPLEX_DTYPES
890-
+ STRING_DTYPES
891-
+ DATETIME64_DTYPES
892-
+ TIMEDELTA64_DTYPES
893-
+ BOOL_DTYPES
894-
+ OBJECT_DTYPES
895-
+ BYTES_DTYPES
896-
)
897-
898-
899-
@pytest.fixture(params=STRING_DTYPES)
865+
@pytest.fixture(params=tm.STRING_DTYPES)
900866
def string_dtype(request):
901867
"""
902868
Parametrized fixture for string dtypes.
@@ -908,7 +874,7 @@ def string_dtype(request):
908874
return request.param
909875

910876

911-
@pytest.fixture(params=BYTES_DTYPES)
877+
@pytest.fixture(params=tm.BYTES_DTYPES)
912878
def bytes_dtype(request):
913879
"""
914880
Parametrized fixture for bytes dtypes.
@@ -919,7 +885,7 @@ def bytes_dtype(request):
919885
return request.param
920886

921887

922-
@pytest.fixture(params=OBJECT_DTYPES)
888+
@pytest.fixture(params=tm.OBJECT_DTYPES)
923889
def object_dtype(request):
924890
"""
925891
Parametrized fixture for object dtypes.
@@ -930,7 +896,7 @@ def object_dtype(request):
930896
return request.param
931897

932898

933-
@pytest.fixture(params=DATETIME64_DTYPES)
899+
@pytest.fixture(params=tm.DATETIME64_DTYPES)
934900
def datetime64_dtype(request):
935901
"""
936902
Parametrized fixture for datetime64 dtypes.
@@ -941,7 +907,7 @@ def datetime64_dtype(request):
941907
return request.param
942908

943909

944-
@pytest.fixture(params=TIMEDELTA64_DTYPES)
910+
@pytest.fixture(params=tm.TIMEDELTA64_DTYPES)
945911
def timedelta64_dtype(request):
946912
"""
947913
Parametrized fixture for timedelta64 dtypes.
@@ -952,7 +918,7 @@ def timedelta64_dtype(request):
952918
return request.param
953919

954920

955-
@pytest.fixture(params=FLOAT_DTYPES)
921+
@pytest.fixture(params=tm.FLOAT_DTYPES)
956922
def float_dtype(request):
957923
"""
958924
Parameterized fixture for float dtypes.
@@ -964,7 +930,7 @@ def float_dtype(request):
964930
return request.param
965931

966932

967-
@pytest.fixture(params=COMPLEX_DTYPES)
933+
@pytest.fixture(params=tm.COMPLEX_DTYPES)
968934
def complex_dtype(request):
969935
"""
970936
Parameterized fixture for complex dtypes.
@@ -976,7 +942,7 @@ def complex_dtype(request):
976942
return request.param
977943

978944

979-
@pytest.fixture(params=SIGNED_INT_DTYPES)
945+
@pytest.fixture(params=tm.SIGNED_INT_DTYPES)
980946
def sint_dtype(request):
981947
"""
982948
Parameterized fixture for signed integer dtypes.
@@ -990,7 +956,7 @@ def sint_dtype(request):
990956
return request.param
991957

992958

993-
@pytest.fixture(params=UNSIGNED_INT_DTYPES)
959+
@pytest.fixture(params=tm.UNSIGNED_INT_DTYPES)
994960
def uint_dtype(request):
995961
"""
996962
Parameterized fixture for unsigned integer dtypes.
@@ -1003,7 +969,7 @@ def uint_dtype(request):
1003969
return request.param
1004970

1005971

1006-
@pytest.fixture(params=ALL_INT_DTYPES)
972+
@pytest.fixture(params=tm.ALL_INT_DTYPES)
1007973
def any_int_dtype(request):
1008974
"""
1009975
Parameterized fixture for any integer dtype.
@@ -1021,7 +987,7 @@ def any_int_dtype(request):
1021987
return request.param
1022988

1023989

1024-
@pytest.fixture(params=ALL_EA_INT_DTYPES)
990+
@pytest.fixture(params=tm.ALL_EA_INT_DTYPES)
1025991
def any_nullable_int_dtype(request):
1026992
"""
1027993
Parameterized fixture for any nullable integer dtype.
@@ -1038,7 +1004,7 @@ def any_nullable_int_dtype(request):
10381004
return request.param
10391005

10401006

1041-
@pytest.fixture(params=ALL_REAL_DTYPES)
1007+
@pytest.fixture(params=tm.ALL_REAL_DTYPES)
10421008
def any_real_dtype(request):
10431009
"""
10441010
Parameterized fixture for any (purely) real numeric dtype.
@@ -1059,7 +1025,7 @@ def any_real_dtype(request):
10591025
return request.param
10601026

10611027

1062-
@pytest.fixture(params=ALL_NUMPY_DTYPES)
1028+
@pytest.fixture(params=tm.ALL_NUMPY_DTYPES)
10631029
def any_numpy_dtype(request):
10641030
"""
10651031
Parameterized fixture for all numpy dtypes.

pandas/tests/dtypes/test_common.py

+20-28
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@
2020
import pandas as pd
2121
import pandas._testing as tm
2222
from pandas.arrays import SparseArray
23-
from pandas.conftest import (
24-
ALL_EA_INT_DTYPES,
25-
ALL_INT_DTYPES,
26-
SIGNED_EA_INT_DTYPES,
27-
SIGNED_INT_DTYPES,
28-
UNSIGNED_EA_INT_DTYPES,
29-
UNSIGNED_INT_DTYPES,
30-
)
3123

3224

3325
# EA & Actual Dtypes
@@ -295,10 +287,10 @@ def test_is_string_dtype():
295287
"dtype",
296288
integer_dtypes
297289
+ [pd.Series([1, 2])]
298-
+ ALL_INT_DTYPES
299-
+ to_numpy_dtypes(ALL_INT_DTYPES)
300-
+ ALL_EA_INT_DTYPES
301-
+ to_ea_dtypes(ALL_EA_INT_DTYPES),
290+
+ tm.ALL_INT_DTYPES
291+
+ to_numpy_dtypes(tm.ALL_INT_DTYPES)
292+
+ tm.ALL_EA_INT_DTYPES
293+
+ to_ea_dtypes(tm.ALL_EA_INT_DTYPES),
302294
)
303295
def test_is_integer_dtype(dtype):
304296
assert com.is_integer_dtype(dtype)
@@ -327,10 +319,10 @@ def test_is_not_integer_dtype(dtype):
327319
"dtype",
328320
signed_integer_dtypes
329321
+ [pd.Series([1, 2])]
330-
+ SIGNED_INT_DTYPES
331-
+ to_numpy_dtypes(SIGNED_INT_DTYPES)
332-
+ SIGNED_EA_INT_DTYPES
333-
+ to_ea_dtypes(SIGNED_EA_INT_DTYPES),
322+
+ tm.SIGNED_INT_DTYPES
323+
+ to_numpy_dtypes(tm.SIGNED_INT_DTYPES)
324+
+ tm.SIGNED_EA_INT_DTYPES
325+
+ to_ea_dtypes(tm.SIGNED_EA_INT_DTYPES),
334326
)
335327
def test_is_signed_integer_dtype(dtype):
336328
assert com.is_integer_dtype(dtype)
@@ -347,10 +339,10 @@ def test_is_signed_integer_dtype(dtype):
347339
np.array(["a", "b"]),
348340
np.array([], dtype=np.timedelta64),
349341
]
350-
+ UNSIGNED_INT_DTYPES
351-
+ to_numpy_dtypes(UNSIGNED_INT_DTYPES)
352-
+ UNSIGNED_EA_INT_DTYPES
353-
+ to_ea_dtypes(UNSIGNED_EA_INT_DTYPES),
342+
+ tm.UNSIGNED_INT_DTYPES
343+
+ to_numpy_dtypes(tm.UNSIGNED_INT_DTYPES)
344+
+ tm.UNSIGNED_EA_INT_DTYPES
345+
+ to_ea_dtypes(tm.UNSIGNED_EA_INT_DTYPES),
354346
)
355347
def test_is_not_signed_integer_dtype(dtype):
356348
assert not com.is_signed_integer_dtype(dtype)
@@ -363,10 +355,10 @@ def test_is_not_signed_integer_dtype(dtype):
363355
"dtype",
364356
unsigned_integer_dtypes
365357
+ [pd.Series([1, 2], dtype=np.uint32)]
366-
+ UNSIGNED_INT_DTYPES
367-
+ to_numpy_dtypes(UNSIGNED_INT_DTYPES)
368-
+ UNSIGNED_EA_INT_DTYPES
369-
+ to_ea_dtypes(UNSIGNED_EA_INT_DTYPES),
358+
+ tm.UNSIGNED_INT_DTYPES
359+
+ to_numpy_dtypes(tm.UNSIGNED_INT_DTYPES)
360+
+ tm.UNSIGNED_EA_INT_DTYPES
361+
+ to_ea_dtypes(tm.UNSIGNED_EA_INT_DTYPES),
370362
)
371363
def test_is_unsigned_integer_dtype(dtype):
372364
assert com.is_unsigned_integer_dtype(dtype)
@@ -383,10 +375,10 @@ def test_is_unsigned_integer_dtype(dtype):
383375
np.array(["a", "b"]),
384376
np.array([], dtype=np.timedelta64),
385377
]
386-
+ SIGNED_INT_DTYPES
387-
+ to_numpy_dtypes(SIGNED_INT_DTYPES)
388-
+ SIGNED_EA_INT_DTYPES
389-
+ to_ea_dtypes(SIGNED_EA_INT_DTYPES),
378+
+ tm.SIGNED_INT_DTYPES
379+
+ to_numpy_dtypes(tm.SIGNED_INT_DTYPES)
380+
+ tm.SIGNED_EA_INT_DTYPES
381+
+ to_ea_dtypes(tm.SIGNED_EA_INT_DTYPES),
390382
)
391383
def test_is_not_unsigned_integer_dtype(dtype):
392384
assert not com.is_unsigned_integer_dtype(dtype)

pandas/tests/indexing/test_categorical.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
Series,
1515
Timedelta,
1616
Timestamp,
17-
conftest,
1817
)
1918
import pandas._testing as tm
2019
from pandas.api.types import CategoricalDtype as CDT
@@ -752,17 +751,17 @@ def test_map_with_dict_or_series(self):
752751
[1.5, 2.5, 3.5],
753752
[-1.5, -2.5, -3.5],
754753
# numpy int/uint
755-
*[np.array([1, 2, 3], dtype=dtype) for dtype in conftest.ALL_INT_DTYPES],
754+
*[np.array([1, 2, 3], dtype=dtype) for dtype in tm.ALL_INT_DTYPES],
756755
# numpy floats
757-
*[np.array([1.5, 2.5, 3.5], dtype=dtyp) for dtyp in conftest.FLOAT_DTYPES],
756+
*[np.array([1.5, 2.5, 3.5], dtype=dtyp) for dtyp in tm.FLOAT_DTYPES],
758757
# numpy object
759758
np.array([1, "b", 3.5], dtype=object),
760759
# pandas scalars
761760
[Interval(1, 4), Interval(4, 6), Interval(6, 9)],
762761
[Timestamp(2019, 1, 1), Timestamp(2019, 2, 1), Timestamp(2019, 3, 1)],
763762
[Timedelta(1, "d"), Timedelta(2, "d"), Timedelta(3, "D")],
764763
# pandas Integer arrays
765-
*[pd.array([1, 2, 3], dtype=dtype) for dtype in conftest.ALL_EA_INT_DTYPES],
764+
*[pd.array([1, 2, 3], dtype=dtype) for dtype in tm.ALL_EA_INT_DTYPES],
766765
# other pandas arrays
767766
pd.IntervalIndex.from_breaks([1, 4, 6, 9]).array,
768767
pd.date_range("2019-01-01", periods=3).array,

pandas/tests/test_algos.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
compat,
3232
)
3333
import pandas._testing as tm
34-
from pandas.conftest import BYTES_DTYPES, STRING_DTYPES
3534
import pandas.core.algorithms as algos
3635
from pandas.core.arrays import DatetimeArray
3736
import pandas.core.common as com
@@ -362,7 +361,7 @@ def test_on_index_object(self):
362361

363362
def test_dtype_preservation(self, any_numpy_dtype):
364363
# GH 15442
365-
if any_numpy_dtype in (BYTES_DTYPES + STRING_DTYPES):
364+
if any_numpy_dtype in (tm.BYTES_DTYPES + tm.STRING_DTYPES):
366365
pytest.skip("skip string dtype")
367366
elif is_integer_dtype(any_numpy_dtype):
368367
data = [1, 2, 2]

0 commit comments

Comments
 (0)