Skip to content

TST: split large tests #39768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pandas/tests/indexing/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def test_loc_listlike_dtypes(self):
with pytest.raises(KeyError, match=re.escape(msg)):
df.loc[["a", "x"]]

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

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

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

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

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

def test_ix_categorical_index_non_unique(self):

# non-unique
df = DataFrame(np.random.randn(3, 3), index=list("ABA"), columns=list("XYX"))
cdf = df.copy()
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/indexing/test_chaining_and_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ def test_setting_with_copy_bug(self):
with pytest.raises(com.SettingWithCopyError, match=msg):
df[["c"]][mask] = df[["b"]][mask]

def test_setting_with_copy_bug_no_warning(self):
# invalid warning as we are returning a new object
# GH 8730
df1 = DataFrame({"x": Series(["a", "b", "c"]), "y": Series(["d", "e", "f"])})
Expand Down
22 changes: 13 additions & 9 deletions pandas/tests/indexing/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_indexing_with_datetime_tz(self):
)
tm.assert_series_equal(result, expected)

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

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

def test_getitem_millisecond_resolution(self, frame_or_series):
# GH#33589

keys = [
"2017-10-25T16:25:04.151",
"2017-10-25T16:25:04.252",
"2017-10-25T16:50:05.237",
"2017-10-25T16:50:05.238",
]
obj = frame_or_series(
[1, 2, 3, 4],
index=[
Timestamp("2017-10-25T16:25:04.151"),
Timestamp("2017-10-25T16:25:04.252"),
Timestamp("2017-10-25T16:50:05.237"),
Timestamp("2017-10-25T16:50:05.238"),
],
index=[Timestamp(x) for x in keys],
)
result = obj["2017-10-25T16:25:04.252":"2017-10-25T16:50:05.237"]
result = obj[keys[1] : keys[2]]
expected = frame_or_series(
[2, 3],
index=[
Timestamp("2017-10-25T16:25:04.252"),
Timestamp("2017-10-25T16:50:05.237"),
Timestamp(keys[1]),
Timestamp(keys[2]),
],
)
tm.assert_equal(result, expected)
48 changes: 32 additions & 16 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def test_inf_upcast(self):
expected = pd.Float64Index([1, 2, np.inf])
tm.assert_index_equal(result, expected)

def test_inf_upcast_empty(self):
# Test with np.inf in columns
df = DataFrame()
df.loc[0, 0] = 1
Expand All @@ -148,26 +149,29 @@ def test_setitem_dtype_upcast(self):
)
tm.assert_frame_equal(df, expected)

@pytest.mark.parametrize("val", [3.14, "wxyz"])
def test_setitem_dtype_upcast2(self, val):

# GH10280
df = DataFrame(
np.arange(6, dtype="int64").reshape(2, 3),
index=list("ab"),
columns=["foo", "bar", "baz"],
)

for val in [3.14, "wxyz"]:
left = df.copy()
left.loc["a", "bar"] = val
right = DataFrame(
[[0, val, 2], [3, 4, 5]],
index=list("ab"),
columns=["foo", "bar", "baz"],
)
left = df.copy()
left.loc["a", "bar"] = val
right = DataFrame(
[[0, val, 2], [3, 4, 5]],
index=list("ab"),
columns=["foo", "bar", "baz"],
)

tm.assert_frame_equal(left, right)
assert is_integer_dtype(left["foo"])
assert is_integer_dtype(left["baz"])
tm.assert_frame_equal(left, right)
assert is_integer_dtype(left["foo"])
assert is_integer_dtype(left["baz"])

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

def test_dups_fancy_indexing_across_dtypes(self):

# across dtypes
df = DataFrame([[1, 2, 1.0, 2.0, 3.0, "foo", "bar"]], columns=list("aaaaaaa"))
df.head()
Expand All @@ -208,6 +214,7 @@ def test_dups_fancy_indexing(self):

tm.assert_frame_equal(df, result)

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

def test_dups_fancy_indexing_only_missing_label(self):

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

# ToDo: check_index_type can be True after GH 11497

def test_dups_fancy_indexing_missing_label(self):

# GH 4619; duplicate indexer with missing label
df = DataFrame({"A": [0, 1, 2]})
with pytest.raises(KeyError, match="with any missing labels"):
Expand All @@ -253,6 +264,8 @@ def test_dups_fancy_indexing(self):
with pytest.raises(KeyError, match="with any missing labels"):
df.loc[[0, 8, 0]]

def test_dups_fancy_indexing_non_unique(self):

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

def test_multi_assign_broadcasting_rhs(self):
# broadcasting on the rhs is required
df = DataFrame(
{
Expand Down Expand Up @@ -781,14 +795,16 @@ def test_non_reducing_slice(self, slc):
tslice_ = non_reducing_slice(slc)
assert isinstance(df.loc[tslice_], DataFrame)

def test_list_slice(self):
@pytest.mark.parametrize("box", [list, Series, np.array])
def test_list_slice(self, box):
# like dataframe getitem
slices = [["A"], Series(["A"]), np.array(["A"])]
subset = box(["A"])

df = DataFrame({"A": [1, 2], "B": [3, 4]}, index=["A", "B"])
expected = pd.IndexSlice[:, ["A"]]
for subset in slices:
result = non_reducing_slice(subset)
tm.assert_frame_equal(df.loc[result], df.loc[expected])

result = non_reducing_slice(subset)
tm.assert_frame_equal(df.loc[result], df.loc[expected])

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