Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ipeaGIT/geobr
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Apr 29, 2024
2 parents 5922b31 + 139b38e commit 79ac551
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 190 deletions.
10 changes: 7 additions & 3 deletions python-package/geobr/list_geobr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pandas as pd
from io import StringIO
from urllib.error import HTTPError

import re

def list_geobr():
"""Prints available functions, according to latest README.md file
Expand All @@ -19,8 +19,12 @@ def list_geobr():

try:
html_data = get("https://github.com/ipeaGIT/geobr/blob/master/README.md").text

df = pd.read_html(StringIO(html_data))[1]
find_emoji = html_data.index("👉")
html_data = html_data[find_emoji:]
escaped_data = html_data.replace("\\u003c", "<").replace("\\u003e", ">")
tables = re.findall("<table>(.+?)</table>", escaped_data)
available_datasets = "<table>" + tables[0].replace("\\n", "") + "</table>"
df = pd.DataFrame(pd.read_html(StringIO(available_datasets))[0])

except HTTPError:
print(
Expand Down
6 changes: 4 additions & 2 deletions python-package/geobr/read_health_facilities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from geobr.utils import select_metadata, download_gpkg


def read_health_facilities(verbose=False):
def read_health_facilities(date=202303, verbose=False):
""" Download geolocated data of health facilities as an sf object.
Data comes from the National Registry of Healthcare facilities (Cadastro Nacional de Estabelecimentos de Saude - CNES),
Expand All @@ -19,6 +19,8 @@ def read_health_facilities(verbose=False):
Parameters
----------
date : Numeric. Date of the data in YYYYMM format. Defaults to `202303`,
which was the latest data available by the time of this update.
verbose : bool, optional
by default False
Expand All @@ -40,7 +42,7 @@ def read_health_facilities(verbose=False):
>>> df = read_health_facilities()
"""

metadata = select_metadata("health_facilities", year=2015, simplified=False)
metadata = select_metadata("health_facilities", year=date, simplified=False)

gdf = download_gpkg(metadata)

Expand Down
2 changes: 1 addition & 1 deletion python-package/geobr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def select_year(metadata, year):
years = ", ".join([str(i) for i in metadata["year"].unique()])

raise Exception(
"Error: Invalid Value to argument year. "
"Error: Invalid Value to argument 'year/date'. "
"It must be one of the following: "
f'{_get_unique_values(metadata, "year")}'
)
Expand Down
455 changes: 274 additions & 181 deletions python-package/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions python-package/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ shapely = "^1.7.0"
python = "^3.9"
requests = "^2.25.1"
lxml = "^5.1.0"
html5lib = "1.1"

[tool.poetry.dev-dependencies]
pytest = "^6.0"
Expand Down
2 changes: 0 additions & 2 deletions python-package/tests/test_list_geobr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@


def test_list_geobr(capsys):

list_geobr()

# Tests whether the function prints output
captured = capsys.readouterr()
assert len(captured.out) > 200
5 changes: 4 additions & 1 deletion python-package/tests/test_read_health_facilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ def test_read_health_facilities():

assert isinstance(df, gpd.geodataframe.GeoDataFrame)

assert len(df) == 360177
assert len(df) == 517629

with pytest.raises(Exception):
read_health_facilities(year=9999999)

with pytest.raises(Exception):
read_health_facilities(year="banana")

0 comments on commit 79ac551

Please sign in to comment.