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

    expected_output = [32.0]

    actual_output = df.median()

    assert actual_output == expected_output
def test_input_int_in_list_of_lists_median_odd():
    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 = [32.0, 4.0]

    actual_output = df.median()

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

    expected_output = [39.5, 4.5]

    actual_output = df.median()

    assert actual_output == expected_output
Exemplo n.º 4
0
def test_median_df():
    data = {
        "value1": [1, 2, 3, 4, 5, 6],
        "value2": [2, 2, 2, 2, 2, 2],
        "value3": [1.1, 2.2, 3.3, 4.4, 5.5, 6.6],
        "value4": ["a", "b", "c", "d", "e", "f"],
    }
    expected_output = np.array([3.5, 2, 3.85, None])
    df = DataFrame(data)
    median_output = df.median()
    print(median_output)
    print(expected_output)

    assert median_output.all() == expected_output.all()
Exemplo n.º 5
0
def test_input_int_in_dict_of_np_median_odd():
    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"]
    )

    expected_output = [32.0, 4.0]

    actual_output = df.median()

    assert actual_output == expected_output
Exemplo n.º 6
0
def test_input_mixed_in_list_of_lists_median_odd():
    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 = [32.1, 4.0, 1.0]

    actual_output = df.median()

    assert actual_output == expected_output
Exemplo n.º 7
0
def test_input_mixed_in_dict_of_np_median_odd():
    obj = {
        "age": np.array([30.1, 53.1, 31.1, 47.1, 32.1]),
        "albums": np.array([4, 10, 2, 5, 4]),
        "C": np.array(["a", "b", "c", "d", "e"]),
        "D": np.array([True, False, True, True, False]),
    }
    df = DataFrame(
        obj,
        colindex=["AGE", "ALBUMS", "C", "D"],
        rowindex=["A", "B", "C", "D", "E"],
    )

    expected_output = [32.1, 4.0, 1.0]

    actual_output = df.median()

    assert actual_output == expected_output
Exemplo n.º 8
0
def test_input_mixed_in_dict_of_lists_median_even():
    obj = {
        "age": [30.1, 53.1, 31.1, 47.1, 32.1, 100.0],
        "albums": [4, 10, 2, 5, 4, 100],
        "C": ["a", "b", "c", "d", "e", "f"],
        "D": [True, False, True, True, False, True],
    }
    df = DataFrame(
        obj,
        colindex=["AGE", "ALBUMS", "C", "D"],
        rowindex=["A", "B", "C", "D", "E", "F"],
    )

    expected_output = [39.6, 4.5, 1.0]

    actual_output = df.median()

    assert actual_output == expected_output
def test_median2():

    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)
    median_collector = []
    columns = []
    for key in dictionary:
        if dictionary[key].dtype == "float64" or \
           dictionary[key].dtype == "int32":
            columns.append(key)
            median_collector.append(statistics.median(dictionary[key]))

    expected_output = median_collector

    output = df.median()

    assert output == expected_output
Exemplo n.º 10
0
def test_median(dictionary, expected):
    myDF = DataFrame(dictionary)
    assert myDF.median() == expected