From d461ef5b5c9f1e9c9feb18f1be9012be428b5f38 Mon Sep 17 00:00:00 2001 From: Claudio Ortega Date: Wed, 21 Aug 2024 19:43:36 +0000 Subject: [PATCH] add param checks to hdx_dataset --- urbanpy/download/download.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/urbanpy/download/download.py b/urbanpy/download/download.py index 04afe00..15ec50c 100644 --- a/urbanpy/download/download.py +++ b/urbanpy/download/download.py @@ -472,6 +472,14 @@ def hdx_dataset(resource): stacklevel=2, ) - hdx_url = f"https://data.humdata.org/dataset/{resource}" + if not resource.ends_with(".csv"): + raise AttributeError("This function only expects a CSV file.") + + if not resource.starts_with("https://data.humdata.org/dataset/"): + hdx_url = f"https://data.humdata.org/dataset/{resource}" + else: + hdx_url = hdx_url + dataset = pd.read_csv(hdx_url) + return dataset