Skip to content

Commit 60a5bc0

Browse files
authored
allow optional arguments in load() (#24)
1 parent 215a7ea commit 60a5bc0

6 files changed

Lines changed: 52 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
Anything MAY change at any time. The public API SHOULD NOT be considered stable.").
1111
While in this phase, we will denote breaking changes with a minor increase.
1212

13-
## Unreleased patch
13+
## 0.4.0
1414

1515
### Changed
1616

17+
* The `load` function in `load.py` can contain optional arguments. Previously no arguments were allowed.
18+
* `load.py` and `schema.py` are publicly accessible under `dac_pkg_name.load` and `dac_pkg_name.schema` respectively. Previously they were marked as private modules, under `dac_pkg_name._load` and `dac_pkg_name._schema`.
19+
* `Schema` does not have to be a `pandera.DataFrameModel` anymore, but any class that implements a `validate` method (see the `_input.interface.Validator` protocol).
1720
* `dac` does not rely on [`pydantic`](https://pypi.org/project/pydantic/) anymore, and uses [`dataclass`](https://docs.python.org/3/library/dataclasses.html#) instead.
1821
Changes affect `PackConfig` and `PyProjectConfig`.
19-
* `Schema` does not have to be a `pandera.DataFrameModel` anymore, but any class that implements a `validate` method (see the `_input.interface.Validator` protocol).
20-
* `load.py` and `schema.py` are publicly accessible under `dac_pkg_name.load` and `dac_pkg_name.schema` respectively. Previously they were marked as private modules, under `dac_pkg_name._load` and `dac_pkg_name._schema`.
2122

2223
## 0.3.3
2324

src/dac/_input/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _check_load_contains_expected_function(self) -> None:
4545

4646
try:
4747
signature = inspect.getfullargspec(pkg.load)
48-
assert signature.args == []
48+
assert len(signature.args) == (len(signature.defaults) if signature.defaults is not None else 0)
4949
except Exception as e:
5050
raise ValueError((f"{self.load_path.as_posix()} does not contain the required `def load()`")) from e
5151

test/data/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ def get_path_to_sample_load_parquet_as_pandas() -> Path:
1717
return Path(__file__).parent / "load/parquet_as_pandas.py"
1818

1919

20+
def get_path_to_sample_load_parquet_as_pandas_with_sample_frac() -> Path:
21+
return Path(__file__).parent / "load/parquet_as_pandas_with_sample_frac.py"
22+
23+
24+
def get_path_to_sample_load_parquet_as_pandas_with_sample_n() -> Path:
25+
return Path(__file__).parent / "load/parquet_as_pandas_with_sample_n.py"
26+
27+
2028
def get_path_to_self_contained_load_as_pandas() -> Path:
2129
return Path(__file__).parent / "load/self_contained_as_pandas.py"
2230

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pathlib import Path
2+
3+
import pandas as pd
4+
5+
6+
def load(sample_frac: float = 1.0) -> pd.DataFrame:
7+
return pd.read_parquet(Path(__file__).parent / "sample.parquet").sample(frac=sample_frac)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from pathlib import Path
2+
3+
import pandas as pd
4+
5+
6+
def load(sample_n: int) -> pd.DataFrame:
7+
return pd.read_parquet(Path(__file__).parent / "sample.parquet").sample(n=sample_n)

test/unit_test/_input/config_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
get_path_to_invalid_load,
55
get_path_to_invalid_schema,
66
get_path_to_sample_load_parquet_as_pandas,
7+
get_path_to_sample_load_parquet_as_pandas_with_sample_frac,
8+
get_path_to_sample_load_parquet_as_pandas_with_sample_n,
79
get_path_to_sample_parquet,
810
get_path_to_sample_schema,
911
get_path_to_schema_incompatible_with_sample_df,
@@ -75,6 +77,29 @@ def test_if_load_does_not_contain_expected_function_then_raise_exception(pyproje
7577
)
7678

7779

80+
def test_if_load_contain_optional_arguments_then_do_not_raise_exception(pyproject: PyProjectConfig):
81+
with TemporaryDirectory() as tmp_dir:
82+
PackConfig(
83+
data_path=get_path_to_sample_parquet(),
84+
load_path=get_path_to_sample_load_parquet_as_pandas_with_sample_frac(),
85+
schema_path=get_path_to_sample_schema(),
86+
wheel_dir=Path(tmp_dir),
87+
pyproject=pyproject,
88+
)
89+
90+
91+
def test_if_load_contain_non_optional_arguments_then_raise_exception(pyproject: PyProjectConfig):
92+
with TemporaryDirectory() as tmp_dir:
93+
with pytest.raises(ValueError):
94+
PackConfig(
95+
data_path=get_path_to_sample_parquet(),
96+
load_path=get_path_to_sample_load_parquet_as_pandas_with_sample_n(),
97+
schema_path=get_path_to_sample_schema(),
98+
wheel_dir=Path(tmp_dir),
99+
pyproject=pyproject,
100+
)
101+
102+
78103
def test_if_invalid_schema_path_then_raise_exception(pyproject: PyProjectConfig):
79104
with TemporaryDirectory() as tmp_dir:
80105
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)