Skip to content

Commit

Permalink
add pragma no cover
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Mathias Schreiner committed Feb 14, 2025
1 parent f2892eb commit 57d11a3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion mllam_data_prep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import importlib.metadata

try: # pragma: no cover
try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError:
__version__ = "unknown"
Expand Down
1 change: 1 addition & 0 deletions mllam_data_prep/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pragma: no cover
import os
from pathlib import Path

Expand Down
8 changes: 4 additions & 4 deletions mllam_data_prep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def validate_config(config_inputs):

for input_dataset_name, input_dataset in config_inputs.items():
if not input_dataset.variables and not input_dataset.derived_variables:
raise InvalidConfigException(
raise InvalidConfigException( # pragma: no cover
f"Input dataset '{input_dataset_name}' is missing the keys `variables` and/or"
" `derived_variables`. Make sure that you update the config so that the input"
f" dataset '{input_dataset_name}' contains at least either a `variables` or"
Expand All @@ -36,7 +36,7 @@ def validate_config(config_inputs):
# Check so that there are no overlapping variables
if isinstance(input_dataset.variables, list):
variable_vars = input_dataset.variables
elif isinstance(input_dataset.variables, dict):
elif isinstance(input_dataset.variables, dict): # pragma: no cover
variable_vars = input_dataset.variables.keys()
else:
raise TypeError(
Expand All @@ -45,7 +45,7 @@ def validate_config(config_inputs):
derived_variable_vars = input_dataset.derived_variables.keys()
common_vars = list(set(variable_vars) & set(derived_variable_vars))
if len(common_vars) > 0:
raise InvalidConfigException(
raise InvalidConfigException( # pragma: no cover
"Both `variables` and `derived_variables` include the following variables name(s):"
f" '{', '.join(common_vars)}'. This is not allowed. Make sure that there"
" are no overlapping variable names between `variables` and `derived_variables`,"
Expand Down Expand Up @@ -382,7 +382,7 @@ class _(JSONWizard.Meta):
raise_on_unknown_json_key = True


if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
import argparse

argparser = argparse.ArgumentParser()
Expand Down
6 changes: 3 additions & 3 deletions mllam_data_prep/create_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .ops.statistics import calc_stats
from .ops.subsetting import extract_variable

if Version(zarr.__version__) >= Version("3"):
if Version(zarr.__version__) >= Version("3"): # pragma: no cover
from zarr.codecs import BloscCodec, BloscShuffle
else:
from numcodecs import Blosc # pragma: no cover
Expand Down Expand Up @@ -53,7 +53,7 @@ def _check_dataset_attributes(ds, expected_attributes, dataset_name):
for key, val in incorrect_attributes.items()
]
)
raise ValueError(
raise ValueError( # pragma: no cover
f"Dataset {dataset_name} has the following incorrect attributes: {s_list}"
)

Expand Down Expand Up @@ -323,7 +323,7 @@ def create_dataset_zarr(fp_config: Path, fp_zarr: Optional[str | Path] = None):

# use zstd compression since it has a good balance of speed and compression ratio
# https://engineering.fb.com/2016/08/31/core-infra/smaller-and-faster-data-compression-with-zstandard/
if Version(zarr.__version__) >= Version("3"):
if Version(zarr.__version__) >= Version("3"): # pragma: no cover
compressor = BloscCodec(cname="zstd", clevel=3, shuffle=BloscShuffle.bitshuffle)
encoding = {v: {"compressors": compressor} for v in ds.data_vars}
else: # pragma: no cover
Expand Down
11 changes: 5 additions & 6 deletions mllam_data_prep/ops/derive_variable/time_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,23 @@ def calculate_day_of_year(time, component):
f" but got {type(time)}."
)

# pragma: no cover
# Cyclic encoding of day of year - use 366 to include leap years!
if component == "sin":
if component == "sin": # pragma: no cover
day_of_year_encoded = np.sin((day_of_year / 366) * 2 * np.pi)
elif component == "cos":
elif component == "cos": # pragma: no cover
day_of_year_encoded = np.cos((day_of_year / 366) * 2 * np.pi)
else:
else: # pragma: no cover
raise ValueError(
f"Invalid value of `component`: '{component}'. Expected one of: 'cos' or 'sin'."
" Please update the config accordingly."
)

if isinstance(day_of_year_encoded, xr.DataArray):
if isinstance(day_of_year_encoded, xr.DataArray): # pragma: no cover
# Add attributes
day_of_year_encoded.name = "day_of_year_" + component
day_of_year_encoded.attrs["long_name"] = (
f"{component.capitalize()} component of cyclically encoded day of year"
)
day_of_year_encoded.attrs["units"] = "1"

return day_of_year_encoded
return day_of_year_encoded # pragma: no cover
2 changes: 1 addition & 1 deletion mllam_data_prep/ops/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def select_by_kwargs(ds, **coord_ranges):

elif isinstance(selection, list): # pragma: no cover
ds = ds.sel({coord: selection})
else:
else: # pragma: no cover
raise NotImplementedError(
f"Selection for coordinate {coord} must be a list or a dict"
)
Expand Down

0 comments on commit 57d11a3

Please sign in to comment.