Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In combine_fragments, cast fragments to list if improperly decoded #548

Merged
merged 11 commits into from
Jul 27, 2023
11 changes: 11 additions & 0 deletions pangeo_forge_recipes/rechunking.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools
import itertools
import logging
import operator
from typing import Dict, Iterator, List, Tuple

Expand All @@ -10,6 +11,8 @@
from .chunk_grid import ChunkGrid
from .types import CombineOp, Dimension, Index, IndexedPosition, Optional

logger = logging.getLogger(__name__)

# group keys are a tuple of tuples like (("lon", 1), ("time", 0))
# the ints are chunk indexes
# code should aways sort the key before emitting it
Expand All @@ -28,6 +31,8 @@ def split_fragment(
:param target_chunks_and_dims: mapping from dimension name to a tuple of (chunksize, dimsize)
"""

logger.info(f"Splitting {fragment = }, with {target_chunks = } and {schema = }")

if target_chunks is None and schema is None:
raise ValueError("Must specify either target_chunks or schema (or both).")
if schema is not None:
Expand Down Expand Up @@ -156,6 +161,12 @@ def combine_fragments(
:param group: the group key; not actually used in combining
:param fragments: indexed dataset fragments
"""
if not isinstance(fragments, list):
# patch for https://github.com/pangeo-forge/pangeo-forge-recipes/issues/552
logger.info(f"Casting `fragments` from {type(fragments) = } to list")
fragments = list(fragments)

logger.info(f"Combining {group = }, containing {fragments = }")

# we are combining over all the concat dims found in the indexes
# first check indexes for consistency
Expand Down
Loading