def test_input_int_in_np_get_row_empty():
    obj = np.array([30, 53, 31, 47, 32])
    df = DataFrame(obj, colindex=["AGE"], rowindex=["A", "B", "C", "D", "E"])

    with pytest.raises(TypeError) as exc_info:
        df.get_row()

    exception_raised = exc_info.value

    assert exception_raised
Пример #2
0
def test_input_int_in_list_get_row_imaginary():
    obj = [30, 53, 31, 47, 32]
    df = DataFrame(obj, colindex=["AGE"], rowindex=["A", "B", "C", "D", "E"])

    with pytest.raises(Exception) as exc_info:
        df.get_row(1 + 2j)

    exception_raised = exc_info.value

    assert exception_raised
def test_input_mixed_in_np_get_row_imaginary():
    obj = np.array([30, 53.0, "31", True, 32])
    df = DataFrame(obj, colindex=["AGE"], rowindex=["A", "B", "C", "D", "E"])

    with pytest.raises(Exception) as exc_info:
        df.get_row(1 + 2j)

    exception_raised = exc_info.value

    assert exception_raised
Пример #4
0
def test_input_int_in_dict_of_lists_get_row_imaginary():
    obj = {"age": [30, 53, 31, 47, 32], "albums": [4, 10, 2, 5, 4]}
    df = DataFrame(obj,
                   colindex=["AGE", "ALBUMS"],
                   rowindex=["A", "B", "C", "D", "E"])

    with pytest.raises(Exception) as exc_info:
        df.get_row(1 + 2j)

    exception_raised = exc_info.value

    assert exception_raised
def test_input_int_in_list_of_lists_get_row_empty():
    obj = [[30, 53, 31, 47, 32], [4, 10, 2, 5, 4]]
    df = DataFrame(obj,
                   colindex=["AGE", "ALBUMS"],
                   rowindex=["A", "B", "C", "D", "E"])

    with pytest.raises(TypeError) as exc_info:
        df.get_row()

    exception_raised = exc_info.value

    assert exception_raised
def test_input_int_in_dict_of_lists_get_row_wrong():
    obj = {
        "age": np.array([30, 53, 31, 47, 32]),
        "albums": np.array([4, 10, 2, 5, 4]),
    }
    df = DataFrame(obj,
                   colindex=["AGE", "ALBUMS"],
                   rowindex=["A", "B", "C", "D", "E"])

    with pytest.raises(Exception) as exc_info:
        df.get_row(100)

    exception_raised = exc_info.value

    assert exception_raised
def test_getrow():
    dictionary = {
        "pet": np.array(["cat", "dog", "mouse"]),
        "age": np.array([1, 2, 3]),
        "weight": np.array([1.0, 2.0, 3.0]),
        "sick": np.array([True, True, False]),
    }
    df = DataFrame(dictionary)

    pet0 = "cat"
    age0 = 1
    weight0 = 1.0
    sick0 = True

    assert df.get_row([0])[0] == pet0
    assert df.get_row([0])[1] == age0
    assert df.get_row([0])[2] == weight0
    assert df.get_row([0])[3] == sick0
def test_input_int_in_np_get_row_by_rowindex():
    obj = np.array([30, 53, 31, 47, 32])
    df = DataFrame(obj, colindex=["AGE"], rowindex=["A", "B", "C", "D", "E"])

    expected_output = [53]

    actual_output = df.get_row("B")

    assert actual_output == expected_output
Пример #9
0
def test_input_int_in_list_get_row_by_index():
    obj = [30, 53, 31, 47, 32]
    df = DataFrame(obj, colindex=["AGE"], rowindex=["A", "B", "C", "D", "E"])

    expected_output = [53]

    actual_output = df.get_row(1)

    assert actual_output == expected_output
def test_input_mixed_in_np_get_row_by_index():
    obj = np.array([30, 53.0, "31", True, 32])
    df = DataFrame(obj, colindex=["AGE"], rowindex=["A", "B", "C", "D", "E"])

    expected_output = ["53.0"]

    actual_output = df.get_row(1)

    assert actual_output == expected_output
Пример #11
0
def test_input_mixed_in_list_of_lists_get_row_imaginary():
    obj = [
        [30.1, 53.1, 31.1, 47.1, 32.1],
        [4, 10, 2, 5, 4],
        ["a", "b", "c", "d", "e"],
        [True, False, True, True, False],
    ]
    df = DataFrame(
        obj,
        colindex=["AGE", "ALBUMS", "C", "D"],
        rowindex=["A", "B", "C", "D", "E"],
    )

    with pytest.raises(Exception) as exc_info:
        df.get_row(1 + 2j)

    exception_raised = exc_info.value

    assert exception_raised
def test_input_int_in_list_of_lists_get_row_by_rowindex():
    obj = [[30, 53, 31, 47, 32], [4, 10, 2, 5, 4]]
    df = DataFrame(obj,
                   colindex=["AGE", "ALBUMS"],
                   rowindex=["A", "B", "C", "D", "E"])

    expected_output = [53, 10]

    actual_output = df.get_row("B")

    assert actual_output == expected_output
Пример #13
0
def test_input_int_in_dict_of_lists_get_row_by_index():
    obj = {"age": [30, 53, 31, 47, 32], "albums": [4, 10, 2, 5, 4]}
    df = DataFrame(obj,
                   colindex=["AGE", "ALBUMS"],
                   rowindex=["A", "B", "C", "D", "E"])

    expected_output = [53, 10]

    actual_output = df.get_row(1)

    assert actual_output == expected_output
Пример #14
0
def test_getrow():

    dictionary = {
        "pet": np.array(["cat", "dog", "mouse"]),
        "age": np.array([1, 2, 3]),
        "weight": np.array([1.0, 2.0, 3.0]),
        "sick": np.array([True, True, False]),
    }

    row0 = ["cat", 1, 1.0, True]
    row1 = ["dog", 2, 2.0, True]

    df = DataFrame(dictionary)

    assert df.get_row([0, 1])[0] == row0
    assert df.get_row([0, 1])[1] == row1
Пример #15
0
def test_input_mixed_in_list_of_lists_get_row_by_index():
    obj = [
        [30.1, 53.1, 31.1, 47.1, 32.1],
        [4, 10, 2, 5, 4],
        ["a", "b", "c", "d", "e"],
        [True, False, True, True, False],
    ]
    df = DataFrame(
        obj,
        colindex=["AGE", "ALBUMS", "C", "D"],
        rowindex=["A", "B", "C", "D", "E"],
    )

    expected_output = [53.1, 10, "b", False]

    actual_output = df.get_row(1)

    assert actual_output == expected_output
Пример #16
0
def test_get_row_no_params():
    # Test whether get_row function returns a ValueError
    # when specifying no row

    # Use pytest structure for testing the error-handling
    with pytest.raises(ValueError) as ValError:
        _data = np.array([
            [1, 1.3254, False, "R1"],
            [3, 4.123, True, "R 2"],
            [3, 1.4, False, "R 3"],
            [2, 14.0, False, "R 4"],
            [12, 41.0, True, "R5"],
        ])

        _columns = ["IntCol", "FloatCol", "BoolCol", "StringCol"]
        _index = [0, 1, 2, 3, 4]

        df = DataFrame(data=_data, columns=_columns)

        output = df.get_row()
Пример #17
0
def test_getrow():
    # Test whether get_row specifying the 4th row
    # returns the 4th row

    _data = np.array([
        [1, 1.3254, False, "R1"],
        [3, 4.123, True, "R 2"],
        [3, 1.4, False, "R 3"],
        [2, 14.0, False, "R 4"],
        [12, 41.0, True, "R5"],
    ])

    _columns = ["IntCol", "FloatCol", "BoolCol", "StringCol"]

    df = DataFrame(data=_data, columns=_columns)
    row = 3
    expected_output = [2, 14.0, False, "R 4"]
    output = df.get_row(row)

    # Test if created object equals the desired object
    assert np.array_equal(output, expected_output)
Пример #18
0
def test_get_negative_row():
    # Tested behaviour: Return row counting from the end
    # when specifying a negative row key.

    _data = np.array([
        [1, 1.3254, False, "R1"],
        [3, 4.123, True, "R 2"],
        [3, 1.4, False, "R 3"],
        [2, 14.0, False, "R 4"],
        [12, 41.0, True, "R5"],
    ])

    _columns = ["IntCol", "FloatCol", "BoolCol", "StringCol"]
    _index = [0, 1, 2, 3, 4]

    df = DataFrame(data=_data, columns=_columns)
    row = -1
    expected_output = [12, 41.0, True, "R5"]
    output = df.get_row(row)

    # Test if created object equals the desired object
    assert np.array_equal(output, expected_output)
Пример #19
0
def test_get_row_string_rowkey():
    # Tests whether get_row function raises a TypeError
    # when specifying a string as row key.

    # Use pytest structure for testing the error-handling
    with pytest.raises(TypeError) as TypError:

        _data = np.array([
            [1, 1.3254, False, "R1"],
            [3, 4.123, True, "R 2"],
            [3, 1.4, False, "R 3"],
            [2, 14.0, False, "R 4"],
            [12, 41.0, True, "R5"],
        ])

        _columns = ["IntCol", "FloatCol", "BoolCol", "StringCol"]
        _index = [0, 1, 2, 3, 4]

        df = DataFrame(data=_data, columns=_columns)

        # Specify string as row index
        row = "a"

        output = df.get_row(row)
Пример #20
0
def test_get_row_errors():
    with pytest.raises(IndexError):
        myDF = DataFrame(npDict1)
        x = myDF.get_row(5)
Пример #21
0
def test_get_row(dictionary, arg, expected):
    myDF = DataFrame(dictionary)
    assert myDF.get_row(arg) == expected