Skip to content

Add tests #47420

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 9 commits into from
Jun 21, 2022
21 changes: 21 additions & 0 deletions pandas/tests/indexes/multi/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,24 @@ def test_union_duplicates(index, request):

result = mi2.union(mi1)
tm.assert_index_equal(result, mi2.sort_values())


@pytest.mark.parametrize(
"levels1, levels2, codes1, codes2, names",
[
(
[["a", "b", "c"], [0, ""]],
[["c", "d", "b"], [""]],
[[0, 1, 2], [1, 1, 1]],
[[0, 1, 2], [0, 0, 0]],
["name1", "name2"],
),
],
)
def test_intersection_lexsort_depth(levels1, levels2, codes1, codes2, names):
# GH#25169
mi1 = MultiIndex(levels=levels1, codes=codes1, names=names)
mi2 = MultiIndex(levels=levels2, codes=codes2, names=names)
mi_int = mi1.intersection(mi2)

assert mi_int.lexsort_depth == 0
17 changes: 17 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
IndexSlice,
MultiIndex,
Period,
PeriodIndex,
Series,
SparseDtype,
Timedelta,
Expand Down Expand Up @@ -2876,6 +2877,22 @@ def test_loc_set_int_dtype():
tm.assert_frame_equal(df, expected)


def test_loc_periodindex_3_levels():
# GH#24091
p_index = PeriodIndex(
["20181101 1100", "20181101 1200", "20181102 1300", "20181102 1400"],
name="datetime",
freq="B",
)
mi_series = DataFrame(
[["A", "B", 1.0], ["A", "C", 2.0], ["Z", "Q", 3.0], ["W", "F", 4.0]],
index=p_index,
columns=["ONE", "TWO", "VALUES"],
)
mi_series = mi_series.set_index(["ONE", "TWO"], append=True)["VALUES"]
assert mi_series.loc[(p_index[0], "A", "B")] == 1.0


class TestLocSeries:
@pytest.mark.parametrize("val,expected", [(2**63 - 1, 3), (2**63, 4)])
def test_loc_uint64(self, val, expected):
Expand Down