Skip to content

Commit

Permalink
add test and param docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
cisaacstern committed Aug 23, 2023
1 parent 230e405 commit e90c5ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pangeo_forge_recipes/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ class StoreToZarr(beam.PTransform, ZarrWriterMixin):
:param combine_dims: The dimensions to combine
:param target_chunks: Dictionary mapping dimension names to chunks sizes.
If a dimension is a not named, the chunks will be inferred from the data.
:param consolidate_metadata: Whether to consolidate metadata in the resulting
Zarr dataset. Defaults to ``True``.
"""

# TODO: make it so we don't have to explicitly specify combine_dims
Expand Down
16 changes: 12 additions & 4 deletions tests/test_transforms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from dataclasses import dataclass

import apache_beam as beam
import pytest
import xarray as xr
Expand Down Expand Up @@ -234,17 +236,22 @@ def _check_chunks(actual):
assert_that(rechunked, correct_chunks())


@pytest.mark.parametrize("consolidate", [True, False])
def test_StoreToZarr_emits_openable_fsstore(
pipeline,
netcdf_local_file_pattern_sequential,
tmp_target_url,
consolidate,
):
def _open_zarr(store):
return xr.open_dataset(store, engine="zarr")
def _open_zarr(store, consolidated):
return xr.open_dataset(store, engine="zarr", consolidated=consolidated)

@dataclass
class OpenZarrStore(beam.PTransform):
consolidated: bool

def expand(self, pcoll):
return pcoll | beam.Map(_open_zarr)
return pcoll | beam.Map(_open_zarr, consolidated=self.consolidated)

def is_xrdataset():
def _is_xr_dataset(actual):
Expand All @@ -261,6 +268,7 @@ def _is_xr_dataset(actual):
target_root=tmp_target_url,
store_name="test.zarr",
combine_dims=pattern.combine_dim_keys,
consolidate_metadata=consolidate,
)
open_store = target_store | OpenZarrStore()
open_store = target_store | OpenZarrStore(consolidated=consolidate)
assert_that(open_store, is_xrdataset())

0 comments on commit e90c5ce

Please sign in to comment.