Skip to content

Commit

Permalink
Added the ability to list datasets (#266)
Browse files Browse the repository at this point in the history
* Added the ability to list datasets

* fix requirements
  • Loading branch information
nwlandry authored Jan 9, 2023
1 parent f20303d commit c6b6ef1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion requirements/default.txt
Original file line number Diff line number Diff line change
@@ -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
19 changes: 13 additions & 6 deletions xgi/readwrite/xgi_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def load_xgi_data(
dataset,
dataset=None,
cache=True,
read=False,
path="",
Expand All @@ -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
Expand Down Expand Up @@ -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
-------
Expand All @@ -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}")

Expand Down

0 comments on commit c6b6ef1

Please sign in to comment.