tests.test_dataframe2memory_dict   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 16
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A test_dataframe2memory_dict() 0 15 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 dataframe2memory_dict
11
12
13
def test_dataframe2memory_dict():
14
    search_space = {"x": list(np.arange(20)), "y": list(np.arange(20))}
15
16
    array = np.array([[0, 0, 0.1, 0.1], [1, 1, 0.2, 0.2], [2, 2, 0.3, 0.3]])
17
    df1 = pd.DataFrame(array, columns=["x", "y", "eval_time", "score"])
18
19
    memory_dict_new = dataframe2memory_dict(df1, search_space)
20
21
    memory_dict = {
22
        (0, 0): {"score": 0.1, "eval_time": 0.1},
23
        (1, 1): {"score": 0.2, "eval_time": 0.2},
24
        (2, 2): {"score": 0.3, "eval_time": 0.3},
25
    }
26
27
    assert memory_dict_new == memory_dict
28