Skip to content

Commit

Permalink
style(repo): Linting and fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
devsjc committed Dec 16, 2024
1 parent 1c8f409 commit 1f23dd8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/nwp_consumer/cmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
from typing import NamedTuple

from nwp_consumer.internal import handlers, ports, repositories, services
from nwp_consumer.internal import handlers, ports, repositories

log = logging.getLogger("nwp-consumer")

Expand Down
1 change: 0 additions & 1 deletion src/nwp_consumer/internal/ports/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import abc
import datetime as dt
import logging
import pathlib
from collections.abc import Callable, Iterator

import xarray as xr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test__download_and_convert(self) -> None:

for url in urls:
with self.subTest(url=url):
result = c._download_and_convert(url)
result = c._download_and_convert(url=url, it=test_it)

self.assertIsInstance(result, Success, msg=f"{result!s}")

Expand Down
29 changes: 16 additions & 13 deletions src/nwp_consumer/internal/services/consumer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ def _fold_dataarrays_generator(
"""
results: list[ResultE[int]] = []
for value in generator:
result: ResultE[int] | list[ResultE[int]] = value.do(
[store.write_to_region(da) for da in das]
for das in value
)
results.extend(result if isinstance(result, list) else [result])
if isinstance(value, Failure):
results.extend([value])
else:
results.extend([store.write_to_region(da=da) for da in value.unwrap()])
successes, failures = partition(results)
# TODO: Define the failure threshold for number of write attempts properly
log.info(f"Processed {len(successes)} DataArrays successfully with {len(failures)} errors.")
Expand All @@ -87,7 +86,8 @@ def _fold_dataarrays_generator(
else:
break
return Failure(OSError(
f"Error threshold exceeded: {len(failures)} errors (>0) occurred during processing.",
"Error threshold exceeded: "
f"{len(failures)} errors (>0) occurred during processing.",
))
else:
return Success(sum(successes))
Expand Down Expand Up @@ -132,13 +132,16 @@ def _create_suitable_store(
period: The period for which to gather init time data.
"""
its: list[dt.datetime] = []
match type(period):
case dt.datetime:
its = [period]
case dt.date:
its = repository_metadata.month_its(year=period.year, month=period.month)
case _:
match period:
case _ if period is None:
its = [repository_metadata.determine_latest_it_from(dt.datetime.now(tz=dt.UTC))]
case single_it if isinstance(period, dt.datetime):
its = [single_it] # type: ignore
case multiple_its if isinstance(period, dt.date):
its = repository_metadata.month_its(
year=multiple_its.year,
month=multiple_its.month,
)

# Create a store for the data with the relevant init time coordinates
return entities.TensorStore.initialize_empty_store(
Expand Down Expand Up @@ -233,5 +236,5 @@ def info(
notification_adaptor: type[ports.NotificationRepository],
) -> str:
"""Get information about the service."""
pass
raise NotImplementedError("Not yet implemented")

0 comments on commit 1f23dd8

Please sign in to comment.