Skip to content

Commit

Permalink
Implement basic domain getter
Browse files Browse the repository at this point in the history
  • Loading branch information
daffidwilde committed Nov 14, 2023
1 parent b840fd0 commit 85f006d
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/centhesus/mst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from census21api import CensusAPI
from census21api.constants import DIMENSIONS_BY_POPULATION_TYPE as DIMENSIONS
from mbi import Domain


class MST:
Expand Down Expand Up @@ -64,7 +65,25 @@ def __init__(
self.domain = self.get_domain()

def _get_domain_of_feature(self, feature):
"""Retrieve the domain for items in a feature of the API."""
"""
Retrieve the domain for items in a feature of the API.
Parameters
----------
feature : {"area-types", "dimensions"}
Feature of the API from which to call.
Raises
------
ValueError
If `feature` is invalid.
Returns
-------
domain : dict
Dictionary containing the domain metadata. Empty if
`feature` is `"area-types"` and `self.area_type` is `None`.
"""

if feature == "area-types" and self.area_type is None:
return {}
Expand All @@ -86,4 +105,19 @@ def _get_domain_of_feature(self, feature):
return domain

def get_domain(self):
"""Retrieve domain metadata from the API."""
"""
Retrieve domain metadata from the API.
Returns
-------
domain : mbi.Domain
Dictionary-like object defining the domain size of every column
in the synthetic dataset (area type and dimensions).
"""

area_type_domain = self._get_domain_of_feature("area-types")
dimension_domain = self._get_domain_of_feature("dimensions")

domain = Domain.fromdict({**area_type_domain, **dimension_domain})

return domain

0 comments on commit 85f006d

Please sign in to comment.