Skip to content

Commit

Permalink
api-client get_dataset_file (#821)
Browse files Browse the repository at this point in the history
* api_client: introduce get_dataset_file

* add test and changlog entry

* update tutorial and tests

* api_client.py in black
  • Loading branch information
emanuel-schmid authored Jan 18, 2024
1 parent 7e9b4f8 commit 5f55a17
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 164 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Code freeze date: YYYY-MM-DD

### Added

- 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)
- Read and Write methods to and from csv files for the `DiscRates` class. [#818](ttps://github.com/CLIMADA-project/climada_python/pull/818)

### Changed
Expand Down
7 changes: 2 additions & 5 deletions climada/engine/unsequa/test/test_unsequa.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,9 @@
TEST_UNC_OUTPUT_IMPACT, TEST_UNC_OUTPUT_COSTBEN)
from climada.util.api_client import Client

apiclient = Client()
ds = apiclient.get_dataset_info(name=TEST_UNC_OUTPUT_IMPACT, status='test_dataset')
_target_dir, [test_unc_output_impact] = apiclient.download_dataset(ds)

ds = apiclient.get_dataset_info(name=TEST_UNC_OUTPUT_COSTBEN, status='test_dataset')
_target_dir, [test_unc_output_costben] = apiclient.download_dataset(ds)
test_unc_output_impact = Client().get_dataset_file(name=TEST_UNC_OUTPUT_IMPACT, status='test_dataset')
test_unc_output_costben = Client().get_dataset_file(name=TEST_UNC_OUTPUT_COSTBEN, status='test_dataset')


def impf_dem(x_paa=1, x_mdd=1):
Expand Down
10 changes: 10 additions & 0 deletions climada/test/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ def test_get_litpop_fail(self):
self.assertIn(" can only query single countries. Download the data for multiple countries individually and concatenate ",
str(cm.exception))

def test_get_dataset_file(self):
client = Client()
with tempfile.TemporaryDirectory() as temp_dir:
single_file = client.get_dataset_file(
name='test_imp_mat', status='test_dataset', # get_dataset_info arguments
target_dir=Path(temp_dir), organize_path=False, # download_dataset arguments
)
self.assertTrue(single_file.is_file())
self.assertEqual(list(Path(temp_dir).iterdir()), [single_file])

def test_multi_filter(self):
client = Client()
testds = client.list_dataset_infos(data_type='storm_europe')
Expand Down
6 changes: 3 additions & 3 deletions climada/test/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
from climada.util.constants import HAZ_DEMO_MAT, ENT_DEMO_TODAY, TEST_UNC_OUTPUT_COSTBEN
from climada.util.api_client import Client

apiclient = Client()
ds = apiclient.get_dataset_info(name=TEST_UNC_OUTPUT_COSTBEN, status='test_dataset')
_target_dir, [test_unc_output_costben] = apiclient.download_dataset(ds)

test_unc_output_costben = Client().get_dataset_file(name=TEST_UNC_OUTPUT_COSTBEN, status='test_dataset')


class TestPlotter(unittest.TestCase):
"""Test plot functions."""
Expand Down
Loading

0 comments on commit 5f55a17

Please sign in to comment.