Error message fix: Finding correct column by using counts of unique values.
MODIFY
pangeo_forge_recipes/recipes/xarray_zarr.py
pangeo_forge_recipes/recipes/xarray_zarr.py
@@ -394,10 +394,10 @@ def calculate_sequence_lens(
all_lens = np.expand_dims(all_lens, 1)
# check that all lens are the same along the concat dim
- unique_vec, unique_idx = np.unique(all_lens, axis=1, return_index=True)
+ unique_vec, unique_idx, unique_counts = np.unique(all_lens, axis=1, return_index=True, return_counts=True)
if len(unique_idx) > 1:
- correct_col = all_lens[:, unique_idx[0]]
+ correct_col = all_lens[:, unique_idx[np.argmax(unique_counts)]]
err_idx = np.where(np.expand_dims(correct_col, 1) != all_lens)
err_pos = list(zip(*err_idx[::-1]))
raise ValueError(

MODIFY
tests/recipe_tests/test_XarrayZarrRecipe.py
tests/recipe_tests/test_XarrayZarrRecipe.py
@@ -509,7 +509,7 @@ def test_calc_sequence_length_errors_multiple_inconsistent_lengths(
"a": {"dims": {"time": [1] * 3, "variables": []}},
"b": {"dims": {"time": [2] * 3, "variables": []}},
"c": {"dims": {"time": [7] + [3] * 2, "variables": []}}, # Inconsistent sequence length
- "d": {"dims": {"time": [4] * 2 + [10], "variables": []}},
+ "d": {"dims": {"time": [4] * 2 + [10], "variables": []}}, # Inconsistent sequence length
}
monkeypatch.setattr(MetadataTarget, "getitems", mock_getitems)

Error message fix: Finding correct column by using counts of unique values.