Esempio n. 1
0
def test_init_scenario_1():

    dict_x = {
        "name": ["Tom", "Harry", "Dick", "Jerry"],
        "age": [10, 20, 30, 40]
    }
    df1 = DataFrame(dict_x)

    expected_output = [
        {
            "name": "Tom",
            "age": 10
        },
        {
            "name": "Harry",
            "age": 20
        },
        {
            "name": "Dick",
            "age": 30
        },
        {
            "name": "Jerry",
            "age": 40
        },
    ]

    actual_output = df1.get_rows(0, 4)

    # assert np.array_equal(actual_output, expected_output)
    assert actual_output == expected_output
def test_colnames():
    dict_x = {
        "name": ["Tom", "Harry", "Dick", "Jerry"],
        "age": [10, 20, 30, 40]
    }

    df1 = DataFrame(dict_x)

    expected_output = ["name", "age"]

    actual_output = df1.column_names()

    assert actual_output == expected_output
def test_median():
    dict_x = {
        "name": ["Tom", "Harry", "Dick", "Jerry"],
        "age": [10, 20, 30, 40],
        "cars": [1, 2, 3, 4],
    }

    df1 = DataFrame(dict_x)

    expected_output = [{"age": 25, "cars": 2.5}]

    actual_output = df1.median()

    assert actual_output == expected_output
Esempio n. 4
0
def test_sum():
    dict_x = {
        "name": ["Tom", "Harry", "Dick", "Jerry"],
        "age": [10, 20, 30, 40],
        "cars": [1, 2, 3, 4],
    }

    df1 = DataFrame(dict_x)

    expected_output = [{'age': 100, 'cars': 10}]

    actual_output = df1.sum()

    assert actual_output == expected_output
Esempio n. 5
0
def test_init_error_scenario_1():

    with pytest.raises(ValueError) as excinfo:
        dict_x = [["Tom", "Harry", "Dick", "Jerry"], [10, 20, 30, 40]]
        df1 = DataFrame(dict_x)
    assert str(
        excinfo.value) == "Wrong_Input_Type: Only dictionary is acceptable"
Esempio n. 6
0
def test_init_error_scenario_4():

    with pytest.raises(ValueError) as excinfo:
        dict_x = {
            "name": ["Tom", "Harry", "Dick", "Jerry"],
            "age": [10, 20, "30", 40]
        }
        df1 = DataFrame(dict_x)
    assert str(
        excinfo.value) == "All the values in a column should be the same type"
Esempio n. 7
0
def test_init_error_scenario_3():

    with pytest.raises(ValueError) as excinfo:
        dict_x = {
            "name": ["Tom", "Harry", "Dick", "Jerry"],
            "age": [None, 20, 30, 40]
        }
        df1 = DataFrame(dict_x)
    assert (
        str(excinfo.value) ==
        "Wrong_Data_Type: Only integer, float,boolean and string are accepted")
Esempio n. 8
0
def test_init_error_scenario_2():

    with pytest.raises(ValueError) as excinfo:
        dict_x = {
            "name": ("Tom", "Harry", "Dick", "Jerry"),
            "age": (10, 20, 30, 40)
        }
        df1 = DataFrame(dict_x)
    assert (
        str(excinfo.value) ==
        "Wrong_Input_Type: Only dictionaryof list or Numpy array is acccepted")
from ie_pandas.DataFrame import DataFrame

import pytest
import numpy as np

dict_x = {"name": ["Tom", "Harry", "Dick", "Jerry"], "age": [10, 20, 30, 40]}
df1 = DataFrame(dict_x)


def test_get_row_scenario_1():

    expected_output = np.array([10, 20, 30, 40])

    actual_output = df1["age"]

    assert np.array_equal(actual_output, expected_output)


def test_get_row_error_scenario_1():

    with pytest.raises(ValueError) as excinfo:
        df1["Nationality"]
    assert (str(excinfo.value) ==
            "Wrong_Column_Name: Column is not present in the DataFrame")
Esempio n. 10
0
import pytest
import numpy as np
from ie_pandas.DataFrame import DataFrame

_dic1 = {
    "name": ["Georges", "Alexandre", "Kelly"],
    "Family": ["Koury", "Trump", "McKinsey"],
    "age": [25, 26, 30],
}

_df = DataFrame(_dic1)

_dic2 = {"a": [3, 4, 5, 6], 1: [3, 4, 5, 6]}

_df2 = DataFrame(_dic2)

_dic3 = {
    "list": [10, 11, 12, 13],
    "numpy": np.array([7, 8, 9, 10]),
    "str": ["a", "b", "c", "d"],
}

_df3 = DataFrame(_dic3)


@pytest.mark.parametrize(
    "expected, colnames",
    [
        (np.array([25, 26, 30]), ("age")),
        (
            np.array([