Beispiel #1
0
def test_basic_assert_index_equal(
    rdata,
    exact,
    check_names,
    rname,
    check_categorical,
    dtype,
):
    p_left = pd.Index([1, 2, 3], name="a", dtype=dtype)
    p_right = pd.Index(rdata, name=rname, dtype=dtype)

    left = cudf.from_pandas(p_left)
    right = cudf.from_pandas(p_right)

    kind = None
    try:
        pd.testing.assert_index_equal(
            p_left,
            p_right,
            exact=exact,
            check_names=check_names,
            check_categorical=check_categorical,
        )
    except BaseException as e:
        kind = type(e)
        msg = str(e)

    if kind is not None:
        if (kind == TypeError) and (msg
                                    == ("Categoricals can only be compared "
                                        "if 'categories' are the same.")):
            kind = AssertionError
        with pytest.raises(kind):
            assert_index_equal(
                left,
                right,
                exact=exact,
                check_names=check_names,
                check_categorical=check_categorical,
            )
    else:
        assert_index_equal(
            left,
            right,
            exact=exact,
            check_names=check_names,
            check_categorical=check_categorical,
        )
Beispiel #2
0
def test_range_index_and_int_index_eqaulity(index, exact):
    pidx1 = pd.RangeIndex(0, stop=5, step=1)
    pidx2 = pd.Index([0, 1, 2, 3, 4])
    idx1 = cudf.from_pandas(pidx1)
    idx2 = index([0, 1, 2, 3, 4])

    kind = None
    try:
        pd.testing.assert_index_equal(pidx1, pidx2, exact=exact)
    except BaseException as e:
        kind = type(e)

    if kind is not None:
        with pytest.raises(kind):
            assert_index_equal(idx1, idx2, exact=exact)
    else:
        assert_index_equal(idx1, idx2, exact=exact)
Beispiel #3
0
def test_multiindex_equal(rdata):
    pidx1 = pd.MultiIndex.from_arrays([[0, 1, 2, 3], ["G", "O", "N", "E"]],
                                      names=("n", "id"))
    pidx2 = pd.MultiIndex.from_arrays(rdata, names=("n", "id"))

    idx1 = cudf.from_pandas(pidx1)
    idx2 = cudf.from_pandas(pidx2)

    kind = None
    try:
        pd.testing.assert_index_equal(pidx1, pidx2)
    except BaseException as e:
        kind = type(e)

    if kind is not None:
        with pytest.raises(kind):
            assert_index_equal(idx1, idx2)
    else:
        assert_index_equal(idx1, idx2)