Skip to content

Commit 61f10dc

Browse files
Codacy is up and running + utils tests #176
1 parent 14c92d7 commit 61f10dc

8 files changed

+36
-34
lines changed

is-ssl.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ channels:
33
- conda-forge
44
- default
55
- anaconda
6+
- gwerbin
67
dependencies:
7-
- numpy=1.20.3
8+
- numpy=1.22.3
89
- scikit-learn=0.24.2
910
- matplotlib=3.4.3
1011
- pandas=1.3.4

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
numpy~=1.20.3
1+
numpy~=1.22.3
22
scikit-learn~=0.24.2
33
matplotlib~=3.4.3
44
pandas~=1.3.4

tests/utils.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
# @Filename: utils.py
4+
# @Author: Daniel Puente Ramírez
5+
# @Time: 16/4/22 16:24
6+
7+
from os.path import join
8+
9+
import pytest
10+
from sklearn.utils import Bunch
11+
12+
from utils import arff_data
13+
14+
15+
@pytest.fixture
16+
def arff_path_file():
17+
return join('datasets', 'iris.arff')
18+
19+
20+
def test_arff_data(arff_path_file):
21+
dataset = arff_data(arff_path_file)
22+
assert isinstance(dataset, Bunch)
23+
dataset1 = arff_data(arff_path_file, ['a', 'b', 'c', 'd'])
24+
assert isinstance(dataset1, Bunch)

utils/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
# @Author: Daniel Puente Ramírez
55
# @Time: 22/12/21 18:05
66

7+
from .arff2dataset import arff_data
8+
9+
__all__ = ['arff_data']

utils/arff2dataset.py

+1-28
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,13 @@
33
# @Filename: arff2dataset.py
44
# @Author: Daniel Puente Ramírez
55
# @Time: 22/12/21 18:05
6-
# @Version: 2.0
6+
# @Version: 3.0
77

8-
import arff
98
import numpy as np
109
from sklearn.preprocessing import LabelEncoder
1110
from sklearn.utils import Bunch
1211

1312

14-
def arff2sk_dataset(dataset_path):
15-
dataset = arff.load(open(dataset_path, 'r'))
16-
dat = np.array(dataset['data'])
17-
tt = np.array(dat[:, -1])
18-
dat = np.delete(dat, -1, 1)
19-
dat[dat == ''] = 0.0
20-
dat = dat.astype(float)
21-
22-
try:
23-
tar_names = np.array(dataset['attributes'][-1][1]).astype(int)
24-
tar = tt.astype(int)
25-
except ValueError:
26-
tar_names = np.array([x for x in range(len(dataset['attributes'][-1][
27-
1]))])
28-
relation = {}
29-
for index, target in enumerate(dataset['attributes'][-1][1]):
30-
relation[target] = index
31-
tar = np.array([relation[t] for t in tt])
32-
33-
att_names = np.array([x[0] for x in dataset['attributes'][:-1]])
34-
dataset = Bunch(data=dat, target=tar, feature_names=att_names,
35-
class_names=tar_names)
36-
37-
return dataset
38-
39-
4013
def arff_data(dataset_path, attr=False):
4114
file = open(dataset_path, 'r')
4215
data = []

utils/custom_plots.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# @Filename: custom_plots.py
44
# @Author: Daniel Puente Ramírez
55
# @Time: 27/1/22 17:27
6-
import numpy as np
76
import matplotlib.pyplot as plt
7+
import numpy as np
88

99

1010
def plot_bar_line(name, metric, precision, data_df, save_path):

utils/reading_tests.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# @Time: 25/1/22 16:01
66

77
from collections.abc import Iterable
8+
89
from numpy import nanmean
910

1011

@@ -127,8 +128,8 @@ def n_samples_values(self, n_samples):
127128

128129
def __eq__(self, other):
129130
return isinstance(other, DatasetResult) and (
130-
self.name() == other.name() and
131-
self.precision() == other.precision()
131+
self.name() == other.name() and
132+
self.precision() == other.precision()
132133
)
133134

134135
def __hash__(self):

utils/threads.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# -python-thread/
44

55

6-
import threading
76
import sys
7+
import threading
88

99

1010
class ReturnValueThread(threading.Thread):

0 commit comments

Comments
 (0)