Skip to content

Error raised when no country is declared in resolve_batch method #1

@jairomelo

Description

@jairomelo

Which makes the country_code Optional worthless.

src/georesolver/resolver.py, lines 1015 - 1018

        for _, row in df_iter:
            place_name = row.get(place_column, "")
            country_code = row.get(country_column) if country_column else None
            place_type = row.get(place_type_column) if place_type_column else None

Full log:

_______________________________________________________________ test_batch_real_df _______________________________________________________________

csv_path = 'tests/data/bautismos_cleaned.csv'

    def test_batch_real_df(csv_path="tests/data/bautismos_cleaned.csv"):
        df = pd.read_csv(csv_path)
        resolver = PlaceResolver([GeoNamesQuery(), WHGQuery(), WikidataQuery(), TGNQuery()],
                                verbose=True, lang="es")
>       results_df = resolver.resolve_batch(df,
                                            place_column="Descriptor Geográfico 2",
                                            show_progress=True)

tests/test_batch.py:123: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/georesolver/resolver.py:1020: in resolve_batch
    coords = self.resolve(
src/georesolver/resolver.py:920: in resolve
    if pycountry.countries.get(alpha_2=country_code) is None and country_code is not None:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.11/site-packages/pycountry/db.py:50: in load_if_needed
    return f(self, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pycountry.ExistingCountries object at 0x1082bc550>, default = None, kw = {}, field = 'alpha_2', value = None

    @lazy_load
    def get(
        self, *, default: Optional[Any] = None, **kw: Optional[str]
    ) -> Optional[Any]:
        if len(kw) != 1:
            raise TypeError("Only one criteria may be given")
        field, value = kw.popitem()
        if not isinstance(value, str):
>           raise LookupError()
E           LookupError

.venv/lib/python3.11/site-packages/pycountry/db.py:164: LookupError

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions