Skip to content

Commit

Permalink
fix: use a private cached function to recover the parquet database (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau authored Sep 21, 2023
2 parents d5af359 + 112bf8b commit 6583c52
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pygaul/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import warnings
from difflib import get_close_matches
from functools import lru_cache
from itertools import product
from pathlib import Path
from typing import List, Union
Expand All @@ -24,6 +25,12 @@
__gaul_asset__ = "FAO/GAUL/2015/level{}"


@lru_cache(maxsize=1)
def _df() -> pd.DataFrame:
"""Get the parquet database."""
return pd.read_parquet(__gaul_data__)


@versionadded(version="0.3.0", reason="Add a Names object to handle names")
class AdmNames(pd.DataFrame):
def __init__(
Expand All @@ -49,7 +56,7 @@ def __init__(

# if a name or admin number is set, we need to filter the dataset accordingly
# if not we will simply consider the world dataset
df = pd.read_parquet(__gaul_data__)
df = _df()
if name or admin:
# set the id we look for and tell the function if its a name or an admin
is_name = True if name else False
Expand Down

0 comments on commit 6583c52

Please sign in to comment.