Skip to content

Commit 5ca1b94

Browse files
author
Serge Rey
committed
Update example notebook for return of dataframe
1 parent 4f3a2d9 commit 5ca1b94

File tree

3 files changed

+349
-701
lines changed

3 files changed

+349
-701
lines changed

libpysal/examples/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
example datasets as well as functions to fetch larger datasets.
33
"""
44

5+
6+
import pandas as pd
57
from .base import example_manager
68
from .remotes import datasets as remote_datasets
79
from .builtin import datasets as builtin_datasets
@@ -20,7 +22,6 @@ def fetch_all():
2022
names = list(datasets.keys())
2123
names.sort()
2224
for name in names:
23-
print(name)
2425
example = datasets[name]
2526
try:
2627
example.download()
@@ -29,8 +30,8 @@ def fetch_all():
2930
example_manager.add_examples(datasets)
3031

3132

32-
def available() -> str:
33-
"""List available datasets."""
33+
def available() -> pd.DataFrame:
34+
"""Return a dataframe with available datasets."""
3435
fetch_all()
3536

3637
return example_manager.available()

libpysal/examples/base.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def get_path(self, file_name, verbose=True) -> Union[str, None]:
148148
if file_name == base_name:
149149
return file_path
150150
if verbose:
151-
print("{} is not a file in this example".format(file_name))
151+
print(f'{file_name} is not a file in this example.')
152152
return None
153153

154154
def downloaded(self) -> bool:
@@ -179,9 +179,7 @@ def explain(self) -> None:
179179
def download(self, path=get_data_home()):
180180
"""Download the files for the example."""
181181

182-
if self.downloaded():
183-
print("Already downloaded")
184-
else:
182+
if not self.downloaded():
185183
request = requests.get(self.download_url)
186184
archive = zipfile.ZipFile(io.BytesIO(request.content))
187185
target = join(path, self.root)
@@ -253,11 +251,10 @@ def load(self, example_name: str) -> Example:
253251
if example.installed:
254252
return example
255253
else:
256-
"Downloading: {}".format(example_name)
257254
example.download()
258255
return example
259256
else:
260-
print("Example not available: {}".format(example_name))
257+
print(f'Example not available: {example_name}')
261258
return None
262259

263260
def download_remotes(self):
@@ -271,7 +268,7 @@ def download_remotes(self):
271268
try:
272269
example.download()
273270
except:
274-
print("Example not downloaded: {}".format(name))
271+
print(f'Example not downloaded: {name}.')
275272

276273
def get_installed_names(self) -> list:
277274
"""Return names of all currently installed datasets."""

0 commit comments

Comments
 (0)