Skip to content

Commit

Permalink
Fix AS, LT, VA countries (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
rth authored Dec 28, 2019
1 parent 1f7bf42 commit ef1c45d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release notes

## Version 0.2.1

*In developpement*

- Fix ``Nominatim`` for AS, LT, VA countries.
- Drop Python 2.7 support.

## Version 0.2.0

*December 24, 2018*
Expand Down
21 changes: 21 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest


def pytest_addoption(parser):
parser.addoption(
"--runslow", action="store_true", default=False, help="run slow tests"
)


def pytest_configure(config):
config.addinivalue_line("markers", "slow: mark test as slow to run")


def pytest_collection_modifyitems(config, items):
if config.getoption("--runslow"):
# --runslow given in cli: do not skip slow tests
return
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)
6 changes: 4 additions & 2 deletions pgeocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"SJ", "SK", "SM", "TH", "TR", "UA", "US", "UY", "VA", "VI",
"WF", "YT", "ZA"]


def _get_url(url):
"""Download contents for a URL"""
res = urllib.request.urlopen(url)
Expand Down Expand Up @@ -87,7 +88,7 @@ def _get_data(country):
with ZipFile(reader) as fh_zip:
with fh_zip.open(country.upper() + '.txt') as fh:
data = pd.read_csv(fh,
sep='\t', header=0,
sep='\t', header=None,
names=DATA_FIELDS,
dtype={'postal_code': str})
if not os.path.exists(STORAGE_DIR):
Expand All @@ -110,7 +111,8 @@ def _index_postal_codes(self):
data_unique = df_unique_cp_group[['latitude', 'longitude']].mean()
valid_keys = set(DATA_FIELDS).difference(
['place_name', 'lattitude', 'longitude', 'postal_code'])
data_unique['place_name'] = df_unique_cp_group['place_name'].apply(', '.join) # noqa
data_unique['place_name'] = df_unique_cp_group['place_name'].apply(
lambda x: ', '.join([str(el) for el in x]))
for key in valid_keys:
data_unique[key] = df_unique_cp_group[key].first()
data_unique = data_unique.reset_index()[DATA_FIELDS]
Expand Down
8 changes: 8 additions & 0 deletions test_pgeocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pgeocode import haversine_distance, Nominatim, GeoDistance



@pytest.fixture
def temp_dir():
path_save = pgeocode.STORAGE_DIR
Expand Down Expand Up @@ -121,6 +122,13 @@ def test_nominatim_query_postal_code_multiple():
for place in res.place_name.values:
assert place in expected_places

@pytest.mark.slow
@pytest.mark.parametrize('country', pgeocode.COUNTRIES_VALID)
def test_nominatim_all_countries(country):
nomi = Nominatim(country)
res = nomi.query_postal_code('00000')
assert isinstance(res, pd.Series)


def test_nominatim_distance_postal_code():

Expand Down

0 comments on commit ef1c45d

Please sign in to comment.