Skip to content

Commit 5f55a17

Browse files
api-client get_dataset_file (#821)
* api_client: introduce get_dataset_file * add test and changlog entry * update tutorial and tests * api_client.py in black
1 parent 7e9b4f8 commit 5f55a17

File tree

6 files changed

+347
-164
lines changed

6 files changed

+347
-164
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Code freeze date: YYYY-MM-DD
1212

1313
### Added
1414

15+
- Convenience method `api_client.Client.get_dataset_file`, combining `get_dataset_info` and `download_dataset`, returning a single file objet. [#821](https://github.com/CLIMADA-project/climada_python/pull/821)
1516
- Read and Write methods to and from csv files for the `DiscRates` class. [#818](ttps://github.com/CLIMADA-project/climada_python/pull/818)
1617

1718
### Changed

climada/engine/unsequa/test/test_unsequa.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,9 @@
4040
TEST_UNC_OUTPUT_IMPACT, TEST_UNC_OUTPUT_COSTBEN)
4141
from climada.util.api_client import Client
4242

43-
apiclient = Client()
44-
ds = apiclient.get_dataset_info(name=TEST_UNC_OUTPUT_IMPACT, status='test_dataset')
45-
_target_dir, [test_unc_output_impact] = apiclient.download_dataset(ds)
4643

47-
ds = apiclient.get_dataset_info(name=TEST_UNC_OUTPUT_COSTBEN, status='test_dataset')
48-
_target_dir, [test_unc_output_costben] = apiclient.download_dataset(ds)
44+
test_unc_output_impact = Client().get_dataset_file(name=TEST_UNC_OUTPUT_IMPACT, status='test_dataset')
45+
test_unc_output_costben = Client().get_dataset_file(name=TEST_UNC_OUTPUT_COSTBEN, status='test_dataset')
4946

5047

5148
def impf_dem(x_paa=1, x_mdd=1):

climada/test/test_api_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ def test_get_litpop_fail(self):
213213
self.assertIn(" can only query single countries. Download the data for multiple countries individually and concatenate ",
214214
str(cm.exception))
215215

216+
def test_get_dataset_file(self):
217+
client = Client()
218+
with tempfile.TemporaryDirectory() as temp_dir:
219+
single_file = client.get_dataset_file(
220+
name='test_imp_mat', status='test_dataset', # get_dataset_info arguments
221+
target_dir=Path(temp_dir), organize_path=False, # download_dataset arguments
222+
)
223+
self.assertTrue(single_file.is_file())
224+
self.assertEqual(list(Path(temp_dir).iterdir()), [single_file])
225+
216226
def test_multi_filter(self):
217227
client = Client()
218228
testds = client.list_dataset_infos(data_type='storm_europe')

climada/test/test_plot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
from climada.util.constants import HAZ_DEMO_MAT, ENT_DEMO_TODAY, TEST_UNC_OUTPUT_COSTBEN
3636
from climada.util.api_client import Client
3737

38-
apiclient = Client()
39-
ds = apiclient.get_dataset_info(name=TEST_UNC_OUTPUT_COSTBEN, status='test_dataset')
40-
_target_dir, [test_unc_output_costben] = apiclient.download_dataset(ds)
38+
39+
test_unc_output_costben = Client().get_dataset_file(name=TEST_UNC_OUTPUT_COSTBEN, status='test_dataset')
40+
4141

4242
class TestPlotter(unittest.TestCase):
4343
"""Test plot functions."""

0 commit comments

Comments
 (0)