Passed
Push — master ( e86b5a...ed1475 )
by Daniel
01:54
created

db_extractor.DataInput   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 55
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 15

5 Methods

Rating   Name   Duplication   Size   Complexity  
A DataInput.fn_internal_store_data_frame_to_excel_file() 0 13 3
A DataInput.fn_internal_store_data_frame_to_json_file() 0 9 3
A DataInput.fn_internal_store_data_frame_to_csv_file() 0 12 3
A DataInput.fn_internal_store_data_frame_to_parquet_file() 0 10 3
A DataInput.fn_internal_store_data_frame_to_pickle_file() 0 9 3
1
"""
2
DataInput - class to handle data storing to disk (from Pandas Data Frame
3
"""
4
5
6
class DataInput:
7
8
    @staticmethod
9
    def fn_internal_store_data_frame_to_csv_file(in_dict):
10
        if in_dict['format'].lower() == 'csv':
11
            try:
12
                in_dict['in data frame'].to_csv(path_or_buf = in_dict['name'],
13
                                                sep = in_dict['field delimiter'],
14
                                                header = True,
15
                                                index = False,
16
                                                encoding = 'utf-8')
17
            except Exception as err:
18
                in_dict['error details'] = err
19
        return in_dict
20
21
    @staticmethod
22
    def fn_internal_store_data_frame_to_excel_file(in_dict):
23
        if in_dict['format'].lower() == 'excel':
24
            try:
25
                in_dict['in data frame'].to_excel(excel_writer = in_dict['name'],
26
                                                  engine = 'xlsxwriter',
27
                                                  freeze_panes = (1, 1),
28
                                                  encoding = 'utf-8',
29
                                                  index = False,
30
                                                  verbose = True)
31
            except Exception as err:
32
                in_dict['error details'] = err
33
        return in_dict
34
35
    @staticmethod
36
    def fn_internal_store_data_frame_to_json_file(in_dict):
37
        if in_dict['format'].lower() == 'json':
38
            try:
39
                in_dict['in data frame'].to_json(path_or_buf = in_dict['name'],
40
                                                 compression = in_dict['compression'])
41
            except Exception as err:
42
                in_dict['error details'] = err
43
        return in_dict
44
45
    @staticmethod
46
    def fn_internal_store_data_frame_to_parquet_file(in_dict):
47
        if in_dict['format'].lower() == 'parquet':
48
            try:
49
                in_dict['in data frame'].to_parquet(path = in_dict['name'],
50
                                                    compression = in_dict['compression'],
51
                                                    use_deprecated_int96_timestamps = True)
52
            except Exception as err:
53
                in_dict['error details'] = err
54
        return in_dict
55
56
    @staticmethod
57
    def fn_internal_store_data_frame_to_pickle_file(in_dict):
58
        if in_dict['format'].lower() == 'pickle':
59
            try:
60
                in_dict['in data frame'].to_pickle(path = in_dict['name'],
61
                                                   compression = in_dict['compression'])
62
            except Exception as err:
63
                in_dict['error details'] = err
64
        return in_dict
65