Skip to content

Commit c4332f7

Browse files
author
Gsaes
committed
Modif
1 parent 4f3e370 commit c4332f7

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

HISTORY.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
=======
22
History
33
=======
4-
0.0.12 (2023-05-31)
4+
0.0.13 (2023-06-07)
55
-------------------
66

7+
* Refacto cross validation
78
* Fix Readme
89
* Add test utils.plot
910

qolmat/utils/data.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import zipfile
3-
from datetime import datetime
43
from math import pi
54
from typing import List, Optional
65
from urllib import request
@@ -13,7 +12,6 @@
1312

1413
def download_data(zipname: str, urllink: str, datapath: str = "data/") -> List[pd.DataFrame]:
1514
path_zip = os.path.join(datapath)
16-
print("Download data")
1715
if not os.path.exists(path_zip + ".zip"):
1816
if not os.path.exists(datapath):
1917
os.mkdir(datapath)

tests/utils/test_data.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
[[1, 2], [3, np.nan], [np.nan, 6]], columns=["a", "b"], index=index_preprocess
3030
)
3131

32+
urllink = "https://archive.ics.uci.edu/ml/machine-learning-databases/00501/"
33+
zipname = "PRSA2017_Data_20130301-20170228"
34+
35+
36+
# @pytest.mark.parametrize("zipname, urllink", [(zipname, urllink)])
37+
# def test_utils_data_download_data(zipname: str, urllink: str, mocker: MockerFixture) -> None:
38+
# mocker.patch("urllib.request.urlretrieve")
39+
# mocker.patch("zipfile.ZipFile")
40+
# list_df_result = data.download_data(zipname, urllink)
41+
3242

3343
@pytest.mark.parametrize("name_data", ["Beijing", "Artificial", "Bug"])
3444
def test_utils_data_get_data(name_data: str, mocker: MockerFixture) -> None:
@@ -67,11 +77,15 @@ def test_utils_data_add_holes(df: pd.DataFrame) -> None:
6777

6878

6979
@pytest.mark.parametrize("name_data", ["Beijing"])
70-
def test_utils_data_get_data_corrupted(name_data: str) -> None:
80+
def test_utils_data_get_data_corrupted(name_data: str, mocker: MockerFixture) -> None:
81+
mock_download = mocker.patch("qolmat.utils.data.download_data", return_value=[df])
82+
mocker.patch("qolmat.utils.data.preprocess_data", return_value=df_preprocess)
7183
df_out = data.get_data_corrupted()
72-
size_df_out = df_out.shape
73-
n = size_df_out[0] * size_df_out[1]
74-
np.testing.assert_allclose(df_out.isna().sum().sum() / n, 0.2, atol=0.1)
84+
df_result = pd.DataFrame(
85+
[[1, 2], [np.nan, np.nan], [np.nan, 6]], columns=["a", "b"], index=index_preprocess
86+
)
87+
assert mock_download.call_count == 1
88+
pd.testing.assert_frame_equal(df_result, df_out)
7589

7690

7791
@pytest.mark.parametrize("df", [df_preprocess])

0 commit comments

Comments
 (0)