From c6b6ef1572e35299b84e54b9eb1c09ca286a82c3 Mon Sep 17 00:00:00 2001 From: Nicholas Landry Date: Mon, 9 Jan 2023 12:50:15 -0500 Subject: [PATCH] Added the ability to list datasets (#266) * Added the ability to list datasets * fix requirements --- requirements/default.txt | 2 +- xgi/readwrite/xgi_data.py | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/requirements/default.txt b/requirements/default.txt index 6e66614b1..0ed826c10 100644 --- a/requirements/default.txt +++ b/requirements/default.txt @@ -1,6 +1,6 @@ numpy>=1.19 scipy>=1.5 pandas>=1.0 -networkx>=2.0 +networkx>=2.0,<3.0 requests>=2.0 matplotlib>=3.3 \ No newline at end of file diff --git a/xgi/readwrite/xgi_data.py b/xgi/readwrite/xgi_data.py index 907b97725..d0ecf8838 100644 --- a/xgi/readwrite/xgi_data.py +++ b/xgi/readwrite/xgi_data.py @@ -12,7 +12,7 @@ def load_xgi_data( - dataset, + dataset=None, cache=True, read=False, path="", @@ -24,9 +24,10 @@ def load_xgi_data( Parameters ---------- - dataset : str + dataset : str, default: None Dataset name. Valid options are the top-level tags of the - index.json file in the xgi-data repository. + index.json file in the xgi-data repository. If None, prints + the list of available datasets. cache : bool, optional Whether to cache the input data read : bool, optional @@ -94,14 +95,15 @@ def download_xgi_data(dataset, path=""): jsonfile.close() -def _request_from_xgi_data(dataset): +def _request_from_xgi_data(dataset=None): """Request a dataset from xgi-data. Parameters ---------- - dataset : str + dataset : str, default: None Dataset name. Valid options are the top-level tags of the - index.json file in the xgi-data repository. + index.json file in the xgi-data repository. If None, prints + the list of available datasets. Returns ------- @@ -123,6 +125,11 @@ def _request_from_xgi_data(dataset): if r.ok: index_data = r.json() + + if dataset is None: + print("Available datasets are the following:") + print(*index_data, sep="\n") + return else: raise XGIError(f"Error: HTTP response {r.status_code}")