Skip to content

Commit

Permalink
refactor assert_valid_explicit_coords and rename dims->sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas committed Mar 28, 2024
1 parent 22f361d commit 55166fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 1 addition & 4 deletions xarray/core/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,8 @@ def __init__(
variables[name] = var

dims = set(d for var in variables.values() for d in var.dims)
sizes = {
d: -1 for d in dims
} # TODO the lengths here are never used, so assert_valid_explicit_coords should be refactored
assert_valid_explicit_coords(
variables, dims=sizes, explicit_coords=list(variables)
variables, dims=dims, explicit_coords=list(variables)
)

if indexes is None:
Expand Down
10 changes: 5 additions & 5 deletions xarray/core/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def merge_coords(

def assert_valid_explicit_coords(
variables: Mapping[Any, Any],
dims: Mapping[Any, int],
dims: Iterable[Any],
explicit_coords: Iterable[Hashable],
) -> None:
"""Validate explicit coordinate names/dims.
Expand Down Expand Up @@ -721,16 +721,16 @@ def merge_core(
collected, prioritized, compat=compat, combine_attrs=combine_attrs
)

dims = calculate_dimensions(variables)
sizes = calculate_dimensions(variables)

coord_names, noncoord_names = determine_coords(coerced)
if compat == "minimal":
# coordinates may be dropped in merged results
coord_names.intersection_update(variables)
if explicit_coords is not None:
assert_valid_explicit_coords(variables, dims, explicit_coords)
assert_valid_explicit_coords(variables, sizes.keys(), explicit_coords)
coord_names.update(explicit_coords)
for dim, size in dims.items():
for dim, size in sizes.items():
if dim in variables:
coord_names.add(dim)
ambiguous_coords = coord_names.intersection(noncoord_names)
Expand All @@ -745,7 +745,7 @@ def merge_core(
combine_attrs,
)

return _MergeResult(variables, coord_names, dims, out_indexes, attrs)
return _MergeResult(variables, coord_names, sizes, out_indexes, attrs)


def merge(
Expand Down

0 comments on commit 55166fc

Please sign in to comment.