diff --git a/mllam_data_prep/__init__.py b/mllam_data_prep/__init__.py index 0a616e8..0f34b13 100644 --- a/mllam_data_prep/__init__.py +++ b/mllam_data_prep/__init__.py @@ -2,7 +2,7 @@ import importlib.metadata -try: # pragma: no cover +try: __version__ = importlib.metadata.version(__name__) except importlib.metadata.PackageNotFoundError: __version__ = "unknown" diff --git a/mllam_data_prep/__main__.py b/mllam_data_prep/__main__.py index fac9210..c2d5563 100644 --- a/mllam_data_prep/__main__.py +++ b/mllam_data_prep/__main__.py @@ -1,3 +1,4 @@ +# pragma: no cover import os from pathlib import Path diff --git a/mllam_data_prep/config.py b/mllam_data_prep/config.py index 8a7ccfd..68c33de 100644 --- a/mllam_data_prep/config.py +++ b/mllam_data_prep/config.py @@ -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" @@ -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( @@ -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`," @@ -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() diff --git a/mllam_data_prep/create_dataset.py b/mllam_data_prep/create_dataset.py index 025ea78..862a18a 100644 --- a/mllam_data_prep/create_dataset.py +++ b/mllam_data_prep/create_dataset.py @@ -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 @@ -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}" ) @@ -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 diff --git a/mllam_data_prep/ops/derive_variable/time_components.py b/mllam_data_prep/ops/derive_variable/time_components.py index 59762f8..d724161 100644 --- a/mllam_data_prep/ops/derive_variable/time_components.py +++ b/mllam_data_prep/ops/derive_variable/time_components.py @@ -92,19 +92,18 @@ 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"] = ( @@ -112,4 +111,4 @@ def calculate_day_of_year(time, component): ) day_of_year_encoded.attrs["units"] = "1" - return day_of_year_encoded + return day_of_year_encoded # pragma: no cover diff --git a/mllam_data_prep/ops/selection.py b/mllam_data_prep/ops/selection.py index 2e7cfd1..55c424a 100644 --- a/mllam_data_prep/ops/selection.py +++ b/mllam_data_prep/ops/selection.py @@ -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" )