Skip to content

Commit

Permalink
code to load packaged files
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Nov 12, 2024
1 parent 499f4b6 commit 2651173
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from __future__ import annotations

import polars as pl
import yaml
from pathlib import Path
from pydantic import BaseModel


Expand All @@ -9,6 +13,11 @@ class StandardizeConfig(BaseModel):
select_columns: list[str]
default_values: dict[str, str]

@classmethod
def load_packaged(cls, name: str) -> StandardizeConfig:
path = Path(__file__).parent / "standardize" / name
return cls.model_validate(yaml.safe_load(path.read_text()))


def _identify_column_correspondence(config: StandardizeConfig, raw_df: pl.DataFrame) -> dict[str, str]:
"""Identifies the correspondence between the columns in the raw dataframe and the standardized columns,
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/to_be_migrated/test_standardize_input_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ def test_standardize(config: StandardizeConfig) -> None:
{"mass": [1, 2, 3], "label": ["a", "b", "c"], "type": ["something", "something", "something"]}
)
pl.testing.assert_frame_equal(result, expected_df)


def test_config_load_packaged() -> None:
config = StandardizeConfig.load_packaged("standardize_main_config.yml")
assert config.select_columns == ["mass", "label", "type"]

0 comments on commit 2651173

Please sign in to comment.