Passed
Push — master ( d5b48a...5a31d8 )
by Simon
01:07
created

optimization_metadata.io_helpers.save_object()   A

Complexity

Conditions 3

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 3
nop 3
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
6
import os
7
import glob
8
import dill
9
import json
10
import pandas as pd
11
12
13
def save_dataframe(path, name, _dataframe):
14
    if not os.path.exists(path):
15
        os.makedirs(path, exist_ok=True)
16
17
    _dataframe.to_csv(path + name + ".csv", index=False)
18
19
20
def load_dataframes(path):
21
    paths = glob.glob(path + "*.csv")
22
23
    dataframe_list = []
24
    for path in paths:
25
        dataframe_list.append(pd.read_csv(path))
26
27
    return dataframe_list
28
29
30
def save_object(path, name, _object):
31
    if not os.path.exists(path):
32
        os.makedirs(path, exist_ok=True)
33
34
    with open(path + name + ".pkl", "wb") as dill_file:
35
        dill.dump(_object, dill_file)
36
37
38
def load_object(path, name):
39
    with open(path + name + ".pkl", "rb") as dill_file:
40
        _object = dill.load(dill_file)
41
42
    return _object
43
44
45
def save_json(path, name, dictionary_):
46
    if not os.path.exists(path):
47
        os.makedirs(path, exist_ok=True)
48
49
    with open(path + name + ".json", "w") as f:
50
        json.dump(dictionary_, f, indent=4)
51
52
53
def load_json(path, name):
54
    with open(path + name + ".json", "r") as f:
55
        dictionary_ = json.load(f)
56
57
    return dictionary_
58