Beispiel #1
0
def test_input_int_in_list_repr_col_index():
    obj = [30, 53, 31, 47, 32]
    df = DataFrame(obj, colindex=["AGE"])

    expected_output = ("   AGE" + "\n" + "0   30" + "\n" + "1   53" + "\n" +
                       "2   31" + "\n" + "3   47" + "\n" + "4   32")

    actual_output = repr(df)

    assert actual_output == expected_output
def test_input_int_in_np_get_row_imaginary():
    obj = np.array([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_list_colindex_both_index_axis():
    obj = [30, 53.0, "31", True, 32]
    df = DataFrame(
        obj, rowindex=["AGE"], colindex=["A", "B", "C", "D", "E"], axis=1
    )

    expected_output = ["A", "B", "C", "D", "E"]

    actual_output = df.colindex

    assert actual_output == expected_output
def test_input_int_in_list_of_lists_df_both_index():
    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 = {"AGE": [30, 53, 31, 47, 32], "ALBUMS": [4, 10, 2, 5, 4]}

    actual_output = df.df

    assert actual_output == expected_output
Beispiel #5
0
def test_initialization_array_cols():
    _data = np.array([
        [1, 2, 3, 4, 5, 6],
        [True, False, False, True, True, True],
        [1.1, 2.2, 3.3, 4.4, 5.5, 6.6],
        ["a", "b", "c", "d", "e", "f"],
    ])

    df = DataFrame(data=_data, dtype="Col")
    # Object Created so Pass Test.
    assert True
def test_input_int_in_np_median_even():
    obj = np.array([30, 53, 31, 47, 32, 100])
    df = DataFrame(obj,
                   colindex=["AGE"],
                   rowindex=["A", "B", "C", "D", "E", "F"])

    expected_output = [39.5]

    actual_output = df.median()

    assert actual_output == expected_output
def test_input_int_in_list_of_lists_repr_no_index():
    obj = [[30, 53, 31, 47, 32], [4, 10, 2, 5, 4]]
    df = DataFrame(obj)

    expected_output = ("    0   1" + "\n" + "0  30   4" + "\n" + "1  53  10" +
                       "\n" + "2  31   2" + "\n" + "3  47   5" + "\n" +
                       "4  32   4")

    actual_output = repr(df)

    assert actual_output == expected_output
Beispiel #8
0
def test_bool_input_in_list():
    artists_age_list = [True, False, True, False, True]

    df1 = DataFrame(artists_age_list, axis=1)

    expected_output = ("      0      1     2      3     4" + "\n" +
                       "0  True  False  True  False  True")

    actual_output = repr(df1)

    assert actual_output == expected_output
def test_input_int_in_dict_of_lists_rowindex_both_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 = ["A", "B", "C", "D", "E"]

    actual_output = df.rowindex

    assert actual_output == expected_output
Beispiel #10
0
def test_input_int_in_dict_of_lists_repr_row_index():
    obj = {"age": [30, 53, 31, 47, 32], "albums": [4, 10, 2, 5, 4]}
    df = DataFrame(obj, rowindex=["A", "B", "C", "D", "E"])

    expected_output = ("   age  albums" + "\n" + "A   30       4" + "\n" +
                       "B   53      10" + "\n" + "C   31       2" + "\n" +
                       "D   47       5" + "\n" + "E   32       4")

    actual_output = repr(df)

    assert actual_output == expected_output
def test_bool_input_in_dict_of_np_array():
    artists_dict_of_lists = [[True, False, True], [False, True, False]]
    np_array = np.array(artists_dict_of_lists)
    dict_of_lists_df = DataFrame(np_array, colindex=["age", "albums"])

    expected_output = ("     age  albums" + "\n" + "0   True   False" + "\n" +
                       "1  False    True" + "\n" + "2   True   False")

    actual_output = repr(dict_of_lists_df)

    assert actual_output == expected_output
Beispiel #12
0
def test_input_int_in_list_of_lists_repr_col_index():
    obj = [[30, 53, 31, 47, 32], [4, 10, 2, 5, 4]]
    df = DataFrame(obj, colindex=["AGE", "ALBUMS"])

    expected_output = ("   AGE  ALBUMS" + "\n" + "0   30       4" + "\n" +
                       "1   53      10" + "\n" + "2   31       2" + "\n" +
                       "3   47       5" + "\n" + "4   32       4")

    actual_output = repr(df)

    assert actual_output == expected_output
Beispiel #13
0
def test_input_int_in_list_of_lists_max():
    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.max()

    assert actual_output == expected_output
Beispiel #14
0
def test_input_int_in_dict_of_lists_repr_col_index_axis():
    obj = {"age": [30, 53, 31, 47, 32], "albums": [4, 10, 2, 5, 4]}
    df = DataFrame(obj, colindex=["V", "W", "X", "Y", "Z"], axis=1)

    expected_output = ("         V   W   X   Y   Z" + "\n" +
                       "age     30  53  31  47  32" + "\n" +
                       "albums   4  10   2   5   4")

    actual_output = repr(df)

    assert actual_output == expected_output
Beispiel #15
0
def test_check_set_None():

    _columns = ["IntCol", "FloatCol", "BoolCol", "StringCol"]
    dframe = DataFrame(data=_data, columns=_columns)
    df = dframe.df

    # set the value
    originalval = df["FloatCol"][1]
    df["FloatCol"][1] = np.NaN

    assert not (df["FloatCol"][1] == originalval)
Beispiel #16
0
def test_input_int_in_list_of_lists_getitem_by_index():
    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 = np.array([4, 10, 2, 5, 4])

    actual_output = df[1]

    assert np.all(actual_output == expected_output)
Beispiel #17
0
def test_check_set_value():

    _columns = ["IntCol", "FloatCol", "BoolCol", "StringCol"]
    dframe = DataFrame(data=_data, columns=_columns)
    df = dframe.df

    # set the value
    expectedval = 2
    df["IntCol"][1] = 2

    assert df["IntCol"][1] == expectedval
Beispiel #18
0
def test_input_mixed_in_list_repr_both_index():
    obj = [30, 53.0, "31", True, 32]

    with pytest.raises(Exception) as exc_info:
        df = DataFrame(obj,
                       colindex=["AGE"],
                       rowindex=["A", "B", "C", "D", "E"])

    exception_raised = exc_info.value

    assert exception_raised
def test_input_int_in_dict_of_lists_repr_no_index():
    obj = {"age": [30, 53, 31, 47, 32], "albums": [4, 10, 2, 5, 4]}
    df = DataFrame(obj)

    expected_output = ("   age  albums" + "\n" + "0   30       4" + "\n" +
                       "1   53      10" + "\n" + "2   31       2" + "\n" +
                       "3   47       5" + "\n" + "4   32       4")

    actual_output = repr(df)

    assert actual_output == expected_output
def test_input_int_in_dict_of_lists_setitem_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"])
    df[0] = [100, 100, 100, 100, 100]

    expected_output = np.array([100, 100, 100, 100, 100])

    actual_output = df[0]

    assert np.all(actual_output == expected_output)
Beispiel #21
0
def test_input_int_in_dict_of_np_repr_wrong_col_index():
    obj = {
        "age": np.array([30, 53, 31, 47, 32]),
        "albums": np.array([4, 10, 2, 5, 4]),
    }

    with pytest.raises(Exception) as exc_info:
        df = DataFrame(obj, colindex=["AGE", "ALBUMS", "TOOMANY"])

    exception_raised = exc_info.value

    assert exception_raised
Beispiel #22
0
def test_input_int_in_list_of_lists_getitem_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(Exception) as exc_info:
        df[""]

    exception_raised = exc_info.value

    assert exception_raised
Beispiel #23
0
def test_input_int_in_dict_of_np_colindex_col_index():
    obj = {
        "age": np.array([30, 53, 31, 47, 32]),
        "albums": np.array([4, 10, 2, 5, 4]),
    }
    df = DataFrame(obj, colindex=["AGE", "ALBUMS"])

    expected_output = ["AGE", "ALBUMS"]

    actual_output = df.colindex

    assert actual_output == expected_output
Beispiel #24
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
Beispiel #25
0
def test_input_int_in_list_of_lists_setitem_inconsistent_type():
    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(Exception) as exc_info:
        df[0] = [100, 100, "100", 100.0, 100]

    exception_raised = exc_info.value

    assert exception_raised
def test_input_int_in_dict_of_lists_setitem_wrong_length_rowindex():
    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["AGE"] = [100]

    exception_raised = exc_info.value

    assert exception_raised
def test_input_int_in_list_df_both_index_axis():
    obj = [30, 53, 31, 47, 32]
    df = DataFrame(obj,
                   rowindex=["AGE"],
                   colindex=["A", "B", "C", "D", "E"],
                   axis=1)

    expected_output = {"A": [30], "B": [53], "C": [31], "D": [47], "E": [32]}

    actual_output = df.df

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

    expected_output = {"age": [30, 53, 31, 47, 32], "albums": [4, 10, 2, 5, 4]}

    actual_output = df.df

    assert actual_output == expected_output
Beispiel #29
0
def test_initialization_dict():

    _data = {
        "value1": [1, 2, 3, 4, 5, 6],
        "value2": [True, False, False, True, True, True],
        "value3": [1.1, 2.2, 3.3, 4.4, 5.5, 6.6],
        "value4": ["a", "b", "c", "d", "e", "f"],
    }

    df = DataFrame(data=_data)

    assert True
def test_input_int_in_list_rowindex_both_index_axis():
    obj = [30, 53, 31, 47, 32]
    df = DataFrame(obj,
                   rowindex=["AGE"],
                   colindex=["A", "B", "C", "D", "E"],
                   axis=1)

    expected_output = ["AGE"]

    actual_output = df.rowindex

    assert actual_output == expected_output