Skip to content

Commit

Permalink
Merge pull request #347 from vss-2/issue-342
Browse files Browse the repository at this point in the history
update read_health_facilities on python
  • Loading branch information
rafapereirabr committed Apr 25, 2024
2 parents 6e87524 + c787d67 commit 139b38e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
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
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 139b38e

Please sign in to comment.