Skip to content

Commit

Permalink
refactor: implement ModelBindingsMapper utilizing a DataFrame
Browse files Browse the repository at this point in the history
This change introduces a refactor of the important ModelBindingsMapper
class using a pandas DataFrame for effecting grouping and aggregation
and a CurryModel utility for partially instantiating a given Pydantic
model with checks running for every partial application, allowing for
fast validation failure.

Closes #170.

Aggregation behavior is now only triggered for actually aggregated
fields, and not for top-level models as well. Therefore this also closes #181.
  • Loading branch information
lu-pl committed Jan 22, 2025
1 parent 1accdca commit 1e67643
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rdfproxy/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from rdfproxy.utils.utils import CurryModel, FieldsBindingsMap


class _ModelBindingsMapper(Generic[_TModelInstance]):
class ModelBindingsMapper(Generic[_TModelInstance]):
"""Utility class for mapping bindings to nested/grouped Pydantic models.
RDFProxy utilizes Pydantic models also as a modelling grammar for grouping
Expand Down Expand Up @@ -125,7 +125,7 @@ def _get_unique_models(models: Iterator[_TModelInstance]) -> list[_TModelInstanc
def _instantiate_grouped_model_from_df(
self, df: pd.DataFrame, model: type[_TModelInstance]
) -> _TModelInstance:
"""Instantiate a grouped model from a pd.DataFrame (a group dataframe).
"""Instantiate a grouped model pd.DataFrame (a group dataframe).
This handles the GROUPED code path in _ModelBindingsMapper._instantiate_models.
"""
Expand Down

0 comments on commit 1e67643

Please sign in to comment.