Skip to content

Commit 86ad5c3

Browse files
authored
TST: split large tests (#39768)
1 parent 61b8fc3 commit 86ad5c3

File tree

4 files changed

+52
-25
lines changed

4 files changed

+52
-25
lines changed

pandas/tests/indexing/test_categorical.py

+6
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ def test_loc_listlike_dtypes(self):
322322
with pytest.raises(KeyError, match=re.escape(msg)):
323323
df.loc[["a", "x"]]
324324

325+
def test_loc_listlike_dtypes_duplicated_categories_and_codes(self):
325326
# duplicated categories and codes
326327
index = CategoricalIndex(["a", "b", "a"])
327328
df = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=index)
@@ -341,9 +342,11 @@ def test_loc_listlike_dtypes(self):
341342
)
342343
tm.assert_frame_equal(res, exp, check_index_type=True)
343344

345+
msg = "The following labels were missing: Index(['x'], dtype='object')"
344346
with pytest.raises(KeyError, match=re.escape(msg)):
345347
df.loc[["a", "x"]]
346348

349+
def test_loc_listlike_dtypes_unused_category(self):
347350
# contains unused category
348351
index = CategoricalIndex(["a", "b", "a", "c"], categories=list("abcde"))
349352
df = DataFrame({"A": [1, 2, 3, 4], "B": [5, 6, 7, 8]}, index=index)
@@ -363,6 +366,7 @@ def test_loc_listlike_dtypes(self):
363366
)
364367
tm.assert_frame_equal(res, exp, check_index_type=True)
365368

369+
msg = "The following labels were missing: Index(['x'], dtype='object')"
366370
with pytest.raises(KeyError, match=re.escape(msg)):
367371
df.loc[["a", "x"]]
368372

@@ -405,6 +409,8 @@ def test_ix_categorical_index(self):
405409
expect = DataFrame(df.loc[:, ["X", "Y"]], index=cdf.index, columns=exp_columns)
406410
tm.assert_frame_equal(cdf.loc[:, ["X", "Y"]], expect)
407411

412+
def test_ix_categorical_index_non_unique(self):
413+
408414
# non-unique
409415
df = DataFrame(np.random.randn(3, 3), index=list("ABA"), columns=list("XYX"))
410416
cdf = df.copy()

pandas/tests/indexing/test_chaining_and_caching.py

+1
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ def test_setting_with_copy_bug(self):
373373
with pytest.raises(com.SettingWithCopyError, match=msg):
374374
df[["c"]][mask] = df[["b"]][mask]
375375

376+
def test_setting_with_copy_bug_no_warning(self):
376377
# invalid warning as we are returning a new object
377378
# GH 8730
378379
df1 = DataFrame({"x": Series(["a", "b", "c"]), "y": Series(["d", "e", "f"])})

pandas/tests/indexing/test_datetime.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test_indexing_with_datetime_tz(self):
3737
)
3838
tm.assert_series_equal(result, expected)
3939

40+
def test_indexing_fast_xs(self):
4041
# indexing - fast_xs
4142
df = DataFrame({"a": date_range("2014-01-01", periods=10, tz="UTC")})
4243
result = df.iloc[5]
@@ -53,6 +54,7 @@ def test_indexing_with_datetime_tz(self):
5354
expected = df.iloc[4:]
5455
tm.assert_frame_equal(result, expected)
5556

57+
def test_setitem_with_expansion(self):
5658
# indexing - setting an element
5759
df = DataFrame(
5860
data=pd.to_datetime(["2015-03-30 20:12:32", "2015-03-12 00:11:11"]),
@@ -234,21 +236,23 @@ def test_loc_setitem_with_existing_dst(self):
234236

235237
def test_getitem_millisecond_resolution(self, frame_or_series):
236238
# GH#33589
239+
240+
keys = [
241+
"2017-10-25T16:25:04.151",
242+
"2017-10-25T16:25:04.252",
243+
"2017-10-25T16:50:05.237",
244+
"2017-10-25T16:50:05.238",
245+
]
237246
obj = frame_or_series(
238247
[1, 2, 3, 4],
239-
index=[
240-
Timestamp("2017-10-25T16:25:04.151"),
241-
Timestamp("2017-10-25T16:25:04.252"),
242-
Timestamp("2017-10-25T16:50:05.237"),
243-
Timestamp("2017-10-25T16:50:05.238"),
244-
],
248+
index=[Timestamp(x) for x in keys],
245249
)
246-
result = obj["2017-10-25T16:25:04.252":"2017-10-25T16:50:05.237"]
250+
result = obj[keys[1] : keys[2]]
247251
expected = frame_or_series(
248252
[2, 3],
249253
index=[
250-
Timestamp("2017-10-25T16:25:04.252"),
251-
Timestamp("2017-10-25T16:50:05.237"),
254+
Timestamp(keys[1]),
255+
Timestamp(keys[2]),
252256
],
253257
)
254258
tm.assert_equal(result, expected)

pandas/tests/indexing/test_indexing.py

+32-16
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def test_inf_upcast(self):
125125
expected = pd.Float64Index([1, 2, np.inf])
126126
tm.assert_index_equal(result, expected)
127127

128+
def test_inf_upcast_empty(self):
128129
# Test with np.inf in columns
129130
df = DataFrame()
130131
df.loc[0, 0] = 1
@@ -148,26 +149,29 @@ def test_setitem_dtype_upcast(self):
148149
)
149150
tm.assert_frame_equal(df, expected)
150151

152+
@pytest.mark.parametrize("val", [3.14, "wxyz"])
153+
def test_setitem_dtype_upcast2(self, val):
154+
151155
# GH10280
152156
df = DataFrame(
153157
np.arange(6, dtype="int64").reshape(2, 3),
154158
index=list("ab"),
155159
columns=["foo", "bar", "baz"],
156160
)
157161

158-
for val in [3.14, "wxyz"]:
159-
left = df.copy()
160-
left.loc["a", "bar"] = val
161-
right = DataFrame(
162-
[[0, val, 2], [3, 4, 5]],
163-
index=list("ab"),
164-
columns=["foo", "bar", "baz"],
165-
)
162+
left = df.copy()
163+
left.loc["a", "bar"] = val
164+
right = DataFrame(
165+
[[0, val, 2], [3, 4, 5]],
166+
index=list("ab"),
167+
columns=["foo", "bar", "baz"],
168+
)
166169

167-
tm.assert_frame_equal(left, right)
168-
assert is_integer_dtype(left["foo"])
169-
assert is_integer_dtype(left["baz"])
170+
tm.assert_frame_equal(left, right)
171+
assert is_integer_dtype(left["foo"])
172+
assert is_integer_dtype(left["baz"])
170173

174+
def test_setitem_dtype_upcast3(self):
171175
left = DataFrame(
172176
np.arange(6, dtype="int64").reshape(2, 3) / 10.0,
173177
index=list("ab"),
@@ -195,6 +199,8 @@ def test_dups_fancy_indexing(self):
195199
expected = Index(["b", "a", "a"])
196200
tm.assert_index_equal(result, expected)
197201

202+
def test_dups_fancy_indexing_across_dtypes(self):
203+
198204
# across dtypes
199205
df = DataFrame([[1, 2, 1.0, 2.0, 3.0, "foo", "bar"]], columns=list("aaaaaaa"))
200206
df.head()
@@ -208,6 +214,7 @@ def test_dups_fancy_indexing(self):
208214

209215
tm.assert_frame_equal(df, result)
210216

217+
def test_dups_fancy_indexing_not_in_order(self):
211218
# GH 3561, dups not in selected order
212219
df = DataFrame(
213220
{"test": [5, 7, 9, 11], "test1": [4.0, 5, 6, 7], "other": list("abcd")},
@@ -232,6 +239,8 @@ def test_dups_fancy_indexing(self):
232239
with pytest.raises(KeyError, match="with any missing labels"):
233240
df.loc[rows]
234241

242+
def test_dups_fancy_indexing_only_missing_label(self):
243+
235244
# List containing only missing label
236245
dfnu = DataFrame(np.random.randn(5, 3), index=list("AABCD"))
237246
with pytest.raises(
@@ -244,6 +253,8 @@ def test_dups_fancy_indexing(self):
244253

245254
# ToDo: check_index_type can be True after GH 11497
246255

256+
def test_dups_fancy_indexing_missing_label(self):
257+
247258
# GH 4619; duplicate indexer with missing label
248259
df = DataFrame({"A": [0, 1, 2]})
249260
with pytest.raises(KeyError, match="with any missing labels"):
@@ -253,6 +264,8 @@ def test_dups_fancy_indexing(self):
253264
with pytest.raises(KeyError, match="with any missing labels"):
254265
df.loc[[0, 8, 0]]
255266

267+
def test_dups_fancy_indexing_non_unique(self):
268+
256269
# non unique with non unique selector
257270
df = DataFrame({"test": [5, 7, 9, 11]}, index=["A", "A", "B", "C"])
258271
with pytest.raises(KeyError, match="with any missing labels"):
@@ -447,6 +460,7 @@ def test_multi_assign(self):
447460
df2.loc[mask, cols] = dft.loc[mask, cols].values
448461
tm.assert_frame_equal(df2, expected)
449462

463+
def test_multi_assign_broadcasting_rhs(self):
450464
# broadcasting on the rhs is required
451465
df = DataFrame(
452466
{
@@ -781,14 +795,16 @@ def test_non_reducing_slice(self, slc):
781795
tslice_ = non_reducing_slice(slc)
782796
assert isinstance(df.loc[tslice_], DataFrame)
783797

784-
def test_list_slice(self):
798+
@pytest.mark.parametrize("box", [list, Series, np.array])
799+
def test_list_slice(self, box):
785800
# like dataframe getitem
786-
slices = [["A"], Series(["A"]), np.array(["A"])]
801+
subset = box(["A"])
802+
787803
df = DataFrame({"A": [1, 2], "B": [3, 4]}, index=["A", "B"])
788804
expected = pd.IndexSlice[:, ["A"]]
789-
for subset in slices:
790-
result = non_reducing_slice(subset)
791-
tm.assert_frame_equal(df.loc[result], df.loc[expected])
805+
806+
result = non_reducing_slice(subset)
807+
tm.assert_frame_equal(df.loc[result], df.loc[expected])
792808

793809
def test_maybe_numeric_slice(self):
794810
df = DataFrame({"A": [1, 2], "B": ["c", "d"], "C": [True, False]})

0 commit comments

Comments
 (0)