Skip to content

Commit baab827

Browse files
moved new fixtures to tests/indexes/conftest.py as they're not used anywhere else for now
1 parent e269b09 commit baab827

File tree

2 files changed

+47
-70
lines changed

2 files changed

+47
-70
lines changed

pandas/conftest.py

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -891,72 +891,3 @@ def index_or_series(request):
891891
See GH#29725
892892
"""
893893
return request.param
894-
895-
896-
_indexes = {
897-
"bool-index": tm.makeBoolIndex(10, name="a"),
898-
"int-index": tm.makeIntIndex(10, name="a"),
899-
"float-index": tm.makeFloatIndex(10, name="a"),
900-
"date-index": tm.makeDateIndex(10, name="a"),
901-
"localized-date-index": tm.makeDateIndex(10, name="a", tz="US/Eastern"),
902-
"period-index": tm.makePeriodIndex(10, name="a"),
903-
"string-index": tm.makeStringIndex(10, name="a"),
904-
"unicode-index": tm.makeUnicodeIndex(10, name="a"),
905-
}
906-
907-
908-
@pytest.fixture(params=_indexes.keys())
909-
def index(request):
910-
"""
911-
Fixture for tests on indexes
912-
913-
copy to avoid mutation, e.g. setting .name
914-
"""
915-
return _indexes[request.param].copy()
916-
917-
918-
_arr = np.random.randn(10)
919-
920-
921-
@pytest.fixture
922-
def int_series():
923-
""" Fixture for Series with random numbers and integer index """
924-
index = _indexes["int-index"].copy()
925-
return pd.Series(_arr, index=index, name=index.name)
926-
927-
928-
_series = {
929-
f"series-with-{i_id}": pd.Series(_arr, index=i, name=i.name)
930-
for i_id, i in _indexes.items()
931-
}
932-
933-
_arr_int = np.random.choice(10, size=10, replace=False)
934-
935-
936-
def _create_narrow_series(data, data_dtype):
937-
""" Helper for the _narrow_series dict """
938-
index = _indexes["int-index"].copy()
939-
return pd.Series(data.astype(data_dtype), index=index, name="a")
940-
941-
942-
_narrow_series = {
943-
"float32-series": _create_narrow_series(_arr, np.float32),
944-
"int8-series": _create_narrow_series(_arr_int, np.int8),
945-
"int16-series": _create_narrow_series(_arr_int, np.int16),
946-
"int32-series": _create_narrow_series(_arr_int, np.int32),
947-
"uint8-series": _create_narrow_series(_arr_int, np.uint8),
948-
"uint16-series": _create_narrow_series(_arr_int, np.uint16),
949-
"uint32-series": _create_narrow_series(_arr_int, np.uint32),
950-
}
951-
952-
_all_objs = {**_indexes, **_series, **_narrow_series}
953-
954-
955-
@pytest.fixture(params=_all_objs.keys())
956-
def index_or_series_obj(request):
957-
"""
958-
Fixture for tests on indexes, series and series with a narrow dtype
959-
960-
copy to avoid mutation, e.g. setting .name
961-
"""
962-
return _all_objs[request.param].copy(deep=True)

pandas/tests/indexes/conftest.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
"unicode": tm.makeUnicodeIndex(100),
1010
"string": tm.makeStringIndex(100),
1111
"datetime": tm.makeDateIndex(100),
12+
"localized-datetime": tm.makeDateIndex(100, tz="US/Eastern"),
1213
"period": tm.makePeriodIndex(100),
1314
"timedelta": tm.makeTimedeltaIndex(100),
1415
"int": tm.makeIntIndex(100),
1516
"uint": tm.makeUIntIndex(100),
1617
"range": tm.makeRangeIndex(100),
1718
"float": tm.makeFloatIndex(100),
18-
"bool": Index([True, False]),
19+
"bool": tm.makeBoolIndex(2),
1920
"categorical": tm.makeCategoricalIndex(100),
2021
"interval": tm.makeIntervalIndex(100),
2122
"empty": Index([]),
@@ -50,3 +51,48 @@ def zero(request):
5051
# For testing division by (or of) zero for Index with length 5, this
5152
# gives several scalar-zeros and length-5 vector-zeros
5253
return request.param
54+
55+
56+
_series = {
57+
f"series-with-{i_id}-index": pd.Series(
58+
np.random.randn(len(i)), index=i, name=i.name
59+
)
60+
for i_id, i in indices_dict.items()
61+
}
62+
63+
64+
def _create_narrow_series(data_dtype):
65+
""" Helper for the _narrow_series dict """
66+
index = indices_dict["int"].copy()
67+
size = len(index)
68+
if np.issubdtype(data_dtype, np.float):
69+
data = np.random.choice(size, size=size, replace=False)
70+
elif np.issubdtype(data_dtype, np.integer):
71+
data = np.random.randn(size)
72+
else:
73+
raise ValueError(f"Received an unexpected data_dtype: {data_dtype}")
74+
75+
return pd.Series(data.astype(data_dtype), index=index, name="a")
76+
77+
78+
_narrow_series = {
79+
"float32-series": _create_narrow_series(np.float32),
80+
"int8-series": _create_narrow_series(np.int8),
81+
"int16-series": _create_narrow_series(np.int16),
82+
"int32-series": _create_narrow_series(np.int32),
83+
"uint8-series": _create_narrow_series(np.uint8),
84+
"uint16-series": _create_narrow_series(np.uint16),
85+
"uint32-series": _create_narrow_series(np.uint32),
86+
}
87+
88+
_all_objs = {**indices_dict, **_series, **_narrow_series}
89+
90+
91+
@pytest.fixture(params=_all_objs.keys())
92+
def index_or_series_obj(request):
93+
"""
94+
Fixture for tests on indexes, series and series with a narrow dtype
95+
96+
copy to avoid mutation, e.g. setting .name
97+
"""
98+
return _all_objs[request.param].copy(deep=True)

0 commit comments

Comments
 (0)