Closed dword4 closed 4 years ago
Thanks @dword4! Absolutely, that's a typo is the field name. It should have been country_name
(with _
) here https://github.com/symerio/pgeocode/blob/5b5d68c3f9b468e04dc3211f9f91aaa453a38db5/pgeocode.py#L22
Would you be interested in making a Pull Request to fix it?
Sure I will take a crack at it, will try to get it up this evening sometime
https://github.com/symerio/pgeocode/pull/35 here we go
Fixed in #35 . Thanks!
Hi, somehow this is still present in v0.3.0.
I checked out the v0.3.0 tag, installed pgeocode in a virtualenv, installed pytest and ran the tests:
pytest -x
============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/vleduc/temp/pgeocode
collected 100 items
test_pgeocode.py .....F
=================================== FAILURES ===================================
___________ test_countries[CA-M5R 1X8-Toronto-H2Z 1A7-Montreal-503] ____________
country = 'CA', pc1 = 'M5R 1X8', location1 = 'Toronto', pc2 = 'H2Z 1A7'
location2 = 'Montreal', distance12 = 503
@pytest.mark.parametrize(
"country, pc1, location1, pc2, location2, distance12",
[
("FR", "91120", "Palaiseau", "67000", "Strasbourg", 400),
("GB", "WC2N 5DU", "London", "BT1 5GS", "Belfast", 518),
# ('AR', 'c1002', 'Buenos-Aires', '62091', 'Rio-Negro', 965), known failure # noqa
("AU", "6837", "Perth", "3000", "melbourne", 2722),
("AU", "6837", "Perth", "0221", "Barton", 3089),
("US", "60605", "Chicago", "94103", "San Francisco", 2984),
("CA", "M5R 1X8", "Toronto", "H2Z 1A7", "Montreal", 503),
("IE", "D01 R2PO", "Dublin", "T12 RW26", "Cork", 219),
],
)
def test_countries(country, pc1, location1, pc2, location2, distance12):
if country == "IE":
pytest.xfail("TODO: Investigate failure for IE")
nomi = Nominatim(country)
res = nomi.query_postal_code(pc1)
assert isinstance(res, pd.Series)
assert _normalize_str(location1) in _normalize_str(res.place_name)
> assert "country_code" in res.index
E AssertionError: assert 'country_code' in Index(['postal_code', 'country code', 'place_name', 'state_name', 'state_code',\n 'county_name', 'county_code', 'community_name', 'community_code',\n 'latitude', 'longitude', 'accuracy'],\n dtype='object')
E + where Index(['postal_code', 'country code', 'place_name', 'state_name', 'state_code',\n 'county_name', 'county_code', 'community_name', 'community_code',\n 'latitude', 'longitude', 'accuracy'],\n dtype='object') = postal_code M5R\ncountry code ... -79.4035\naccuracy 6.0\nName: 0, dtype: object.index
test_pgeocode.py:55: AssertionError
=========================== short test summary info ============================
FAILED test_pgeocode.py::test_countries[CA-M5R 1X8-Toronto-H2Z 1A7-Montreal-503]
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
========================= 1 failed, 5 passed in 1.22s ==========================
There seems to be some inconsistency with how to access data returned by the query_postal_code() function in addition to some errors thrown.
pgeocode==0.2.1 pandas==1.0.3
Here is the creation of the object with a postal code
Now I will try to access s.country_code and get an error
And now another field with the same underscore styled name
Now using the manner that is often seen with Pandas
But when I try this for postal code it throws a different error