tests.test_memory_dict2dataframe   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 17
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A test_memory_dict2dataframe() 0 16 1
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
import pytest
6
import numpy as np
7
import pandas as pd
8
from pandas.testing import assert_frame_equal
9
10
from optimization_metadata.memory_conv import memory_dict2dataframe
11
12
13
def test_memory_dict2dataframe():
14
    search_space = {"x": list(np.arange(20)), "y": list(np.arange(20))}
15
16
    memory_dict = {
17
        (0, 0): {"score": 0.1, "eval_time": 0.1},
18
        (1, 1): {"score": 0.2, "eval_time": 0.2},
19
        (2, 2): {"score": 0.3, "eval_time": 0.3},
20
    }
21
22
    dataframe = memory_dict2dataframe(memory_dict, search_space)
23
24
    array = np.array([[0, 0, 0.1, 0.1], [1, 1, 0.2, 0.2], [2, 2, 0.3, 0.3]])
25
    df1 = pd.DataFrame(array, columns=["x", "y", "score", "eval_time"])
26
    df1 = df1[dataframe.columns]
27
28
    assert_frame_equal(df1, dataframe, check_dtype=False)
29