make FilePatternIndex not care about order
MODIFY
pangeo_forge_recipes/patterns.py
pangeo_forge_recipes/patterns.py
@@ -137,9 +137,17 @@ class FilePattern:
def __getitem__(self, indexer: FilePatternIndex) -> str:
"""Get a filename path for a particular key. """
assert len(indexer) == len(self.combine_dims)
- format_function_kwargs = {
- idx.name: dim.keys[idx.index] for idx, dim in zip(indexer, self.combine_dims)
- }
+ format_function_kwargs = {}
+ for idx in indexer:
+ dims = [
+ dim
+ for dim in self.combine_dims
+ if dim.name == idx.name and dim.operation == idx.operation
+ ]
+ if len(dims) != 1:
+ raise KeyError(r"Could not valid combine_dim for indexer {idx}")
+ dim = dims[0]
+ format_function_kwargs[dim.name] = dim.keys[idx.index]
fname = self.format_function(**format_function_kwargs)
return fname

MODIFY
tests/test_patterns.py
tests/test_patterns.py
@@ -76,6 +76,8 @@ def test_file_pattern_concat_merge(pickle):
assert k.operation == CombineOp.MERGE
assert k.sequence_len == 2
assert fp[key] == expected_fname
+ # make sure key order doesn't matter
+ assert fp[key[::-1]] == expected_fname
@pytest.mark.parametrize("nkeep", [1, 2])

make FilePatternIndex not care about order