66from pandas .testing import assert_frame_equal , assert_series_equal
77
88import skrub .datasets
9+ from skrub .conftest import xfail_with_download_error
910from skrub .datasets import _fetching , _utils
1011
1112
1213def _get_table_names_from_bunch (bunch ):
1314 return [k for k in bunch if isinstance (bunch [k ], pd .DataFrame )]
1415
1516
17+ @xfail_with_download_error
1618@pytest .mark .parametrize ("dataset_name" , ["employee_salaries" , "drug_directory" ])
1719def test_fetching (monkeypatch , dataset_name ):
1820 with TemporaryDirectory () as temp_dir :
@@ -39,6 +41,7 @@ def _error_on_get(*args, **kwargs):
3941 assert bunch ["metadata" ] == local_bunch ["metadata" ]
4042
4143
44+ @xfail_with_download_error
4245def test_fetch_credit_fraud ():
4346 data = skrub .datasets .fetch_credit_fraud ()
4447 assert data .baskets .shape == (61241 , 2 )
@@ -52,6 +55,7 @@ def test_fetch_credit_fraud():
5255 skrub .datasets .fetch_credit_fraud (split = None )
5356
5457
58+ @xfail_with_download_error
5559def test_fetch_employee_salaries ():
5660 data = skrub .datasets .fetch_employee_salaries ()
5761 assert data .employee_salaries .shape == (9228 , 9 )
@@ -65,6 +69,48 @@ def test_fetch_employee_salaries():
6569 skrub .datasets .fetch_employee_salaries (split = None )
6670
6771
72+ @xfail_with_download_error
73+ @pytest .mark .parametrize (
74+ "dataset_name, shape" ,
75+ [
76+ ("medical_charge" , (163065 , 12 )),
77+ ("midwest_survey" , (2494 , 29 )),
78+ ("open_payments" , (73558 , 6 )),
79+ ("traffic_violations" , (1578154 , 43 )),
80+ ("toxicity" , (1000 , 2 )),
81+ ("videogame_sales" , (16572 , 11 )),
82+ ("bike_sharing" , (17379 , 11 )),
83+ ],
84+ )
85+ def test_datasets_without_splitting (dataset_name , shape ):
86+ "Test datasets that do not have a split argument in their fetching function."
87+ data = getattr (_fetching , f"fetch_{ dataset_name } " )()
88+ assert data [dataset_name ].shape == shape
89+
90+
91+ @xfail_with_download_error
92+ @pytest .mark .parametrize (
93+ "dataset_name, keys" ,
94+ [
95+ ("flight_delays" , ["flights" , "airports" , "weather" , "stations" , "metadata" ]),
96+ (
97+ "country_happiness" ,
98+ [
99+ "happiness_report" ,
100+ "happiness_report" ,
101+ "life_expectancy" ,
102+ "legal_rights_index" ,
103+ ],
104+ ),
105+ ("movielens" , ["movies" , "ratings" , "metadata" ]),
106+ ],
107+ )
108+ def test_fetching_several_tables (dataset_name , keys ):
109+ "Test fetching functions that return several tables."
110+ data = getattr (_fetching , f"fetch_{ dataset_name } " )()
111+ assert all (key in data .keys () for key in keys )
112+
113+
68114def test_fetching_wrong_checksum (monkeypatch ):
69115 dataset_info = _utils .DATASET_INFO ["employee_salaries" ]
70116 monkeypatch .setitem (dataset_info , "sha256" , "bad_checksum" )
0 commit comments