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

Set construct error message #105

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
set_construct message
  • Loading branch information
davidhassell committed Jul 28, 2020
commit 239bbc556a29791b765971cea27776f5b85b2d20
44 changes: 22 additions & 22 deletions cf/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -2515,7 +2515,7 @@ def _equivalent_coordinate_references(self, field1, key0, key1,
return True

def _set_construct_parse_axes(self, item, axes=None, allow_scalar=True):
'''TODO
'''Parse axes for the set_construct method.

:Parameters:

Expand Down Expand Up @@ -2546,26 +2546,30 @@ def _set_construct_parse_axes(self, item, axes=None, allow_scalar=True):

if not shape or len(shape) != len(set(shape)):
raise ValueError(
"Can't insert {0}: Ambiguous shape: {1}. "
"Can't insert {!r}: Ambiguous shape: {}. "
"Consider setting the 'axes' parameter.".format(
item.__class__.__name__, shape)
item, shape)
)

axes = []
axes_sizes = [domain_axis.get_size(None)
for domain_axis in self.domain_axes.values()]
for n in shape:
if not axes_sizes.count(n):
raise ValueError(
"Can't insert {!r}: There is no "
"domain axis construct with size {}.".format(
item, n)
)

if axes_sizes.count(n) == 1:
axes.append(
self.domain_axes.filter_by_size(n).key())
else:
raise ValueError(
"Can't insert {} {}: Ambiguous shape: {}. "
"Can't insert {!r}: Ambiguous shape: {}. "
"Consider setting the 'axes' "
"parameter.".format(
item.identity(), item.__class__.__name__,
shape
)
"parameter.".format(item, shape)
)
else:
# --------------------------------------------------------
Expand All @@ -2584,29 +2588,27 @@ def _set_construct_parse_axes(self, item, axes=None, allow_scalar=True):

if len(axes) != ndim or len(set(axes)) != ndim:
raise ValueError(
"Can't insert {} {}: Incorrect number of given axes "
"Can't insert {!r}: Incorrect number of given axes "
"(got {}, expected {})".format(
item.identity(), item.__class__.__name__,
len(set(axes)), ndim
)
item, len(set(axes)), ndim)
)

axes2 = []
for axis, size in zip(axes, item.data.shape):
dakey = self.domain_axis(axis, key=True, default=ValueError(
"Unknown axis: {!r}".format(axis)))
dakey = self.domain_axis(
axis, key=True,
default=ValueError(
"Unknown axis: {!r}".format(axis)))
# dakey = self.domain_axis(axis, key=True, default=None)
# if axis is None:
# raise ValueError("Unknown axis: {!r}".format(axis))

axis_size = self.domain_axes[dakey].get_size(None)
if size != axis_size:
raise ValueError(
"Can't insert {} {}: Mismatched axis size "
"Can't insert {!r}: Mismatched axis size "
"({} != {})".format(
item.identity(), item.__class__.__name__,
size, axis_size
)
item, size, axis_size)
)

axes2.append(dakey)
Expand All @@ -2616,11 +2618,9 @@ def _set_construct_parse_axes(self, item, axes=None, allow_scalar=True):

if ndim != len(set(axes)):
raise ValueError(
"Can't insert {} {}: Mismatched number of axes "
"Can't insert {!r}: Mismatched number of axes "
"({} != {})".format(
item.identity(), item.__class__.__name__,
len(set(axes)), ndim
)
item, len(set(axes)), ndim)
)
# --- End: if

Expand Down