Skip to content

Commit

Permalink
Fix Validator documentation. Convert to date in Validator (#369)
Browse files Browse the repository at this point in the history
* Fix Validator documentation. Convert to date in Validator

* Add client type narrowing
  • Loading branch information
mallport authored Apr 4, 2024
1 parent d200930 commit a64af93
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ A `sid_snapshot_date` can also be specified to validate that the field values ca

```python
from dapla_pseudo import Validator
from dapla_pseudo.utils import convert_to_date
import polars as pl

file_path="data/personer.csv"
Expand All @@ -128,7 +127,7 @@ result = (
Validator.from_polars(df)
.on_field("fnr")
.validate_map_to_stable_id(
sid_snapshot_date=convert_to_date("2023-08-29")
sid_snapshot_date="2023-08-29"
)
)
# Show metadata about the validation (e.g. which version of the SID catalog was used)
Expand Down
5 changes: 4 additions & 1 deletion src/dapla_pseudo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def find_multipart_obj(obj_name: str, multipart_files_tuple: set[t.Any]) -> t.An


def convert_to_date(sid_snapshot_date: t.Optional[date | str]) -> t.Optional[date]:
"""Converts the SID version date to the 'date' type."""
"""Converts the SID version date to the 'date' type, if it is a string.
If None, simply passes the None through the function.
"""
if isinstance(sid_snapshot_date, str):
try:
return date.fromisoformat(sid_snapshot_date)
Expand Down
2 changes: 1 addition & 1 deletion src/dapla_pseudo/v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _post_to_sid_endpoint(
self,
path: str,
values: list[str],
sid_snapshot_date: t.Optional[str | date] = None,
sid_snapshot_date: t.Optional[date] = None,
stream: bool = False,
) -> requests.Response:
request: dict[str, t.Collection[str]] = {"fnrList": values}
Expand Down
3 changes: 2 additions & 1 deletion src/dapla_pseudo/v1/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import polars as pl
import requests

from dapla_pseudo.utils import convert_to_date
from dapla_pseudo.utils import get_file_format_from_file_name
from dapla_pseudo.v1.client import _client
from dapla_pseudo.v1.pseudo_commons import PseudoFieldResponse
Expand Down Expand Up @@ -115,7 +116,7 @@ def validate_map_to_stable_id(
response: requests.Response = _client()._post_to_sid_endpoint(
"sid/lookup/batch",
self._dataframe[self._field].to_list(),
sid_snapshot_date,
convert_to_date(sid_snapshot_date),
stream=True,
)
# The response content is received as a buffered byte stream from the server.
Expand Down

0 comments on commit a64af93

Please sign in to comment.