-
Notifications
You must be signed in to change notification settings - Fork 284
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
Dask merge concat fill value #2520
Changes from 5 commits
74e8290
703a49a
f6a46aa
fb0a3a5
e222205
d44458d
414c362
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,11 +407,6 @@ def match(self, other, error_on_mismatch): | |
if self.data_type != other.data_type: | ||
msg = 'cube data dtype differs: {} != {}' | ||
msgs.append(msg.format(self.data_type, other.data_type)) | ||
if self.fill_value != other.fill_value: | ||
# Allow fill-value promotion if either fill-value is None. | ||
if self.fill_value is not None and other.fill_value is not None: | ||
msg = 'cube fill value differs: {} != {}' | ||
msgs.append(msg.format(self.fill_value, other.fill_value)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you choose to allow for merging and concatenating cubes with different fill values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lbdreyer This is more in alignment with the behaviour of It also aligns with the behaviour of With regards to cubes, we're doing the same now in this PR - if we have two cubes that only differ on |
||
if (self.cell_measures_and_dims != other.cell_measures_and_dims): | ||
msgs.append('cube.cell_measures differ') | ||
|
||
|
@@ -1285,15 +1280,19 @@ def register(self, cube, error_on_mismatch=False): | |
this :class:`ProtoCube`. | ||
|
||
""" | ||
signature = self._cube_signature | ||
cube_signature = self._cube_signature | ||
other = self._build_signature(cube) | ||
match = signature.match(other, error_on_mismatch) | ||
match = cube_signature.match(other, error_on_mismatch) | ||
if match: | ||
if signature.fill_value is None and other.fill_value is not None: | ||
# Perform proto-cube fill-value promotion. | ||
fv = other.fill_value | ||
self._cube_signature = self._build_signature(self._source, | ||
fill_value=fv) | ||
# Determine whether the fill value requires to be demoted | ||
# to the default value. | ||
if cube_signature.fill_value is not None: | ||
if other.fill_value is None or \ | ||
cube_signature.fill_value != other.fill_value: | ||
# Demote the fill value to the default. | ||
signature = self._build_signature(self._source, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One is a class instance (writable) the other is a specialization of a |
||
default_fill_value=True) | ||
self._cube_signature = signature | ||
coord_payload = self._extract_coord_payload(cube) | ||
match = coord_payload.match_signature(self._coord_signature, | ||
error_on_mismatch) | ||
|
@@ -1614,7 +1613,7 @@ def _build_coordinates(self): | |
self._vector_aux_coords_dims): | ||
aux_coords_and_dims.append(_CoordAndDims(item.coord, dims)) | ||
|
||
def _build_signature(self, cube, fill_value=None): | ||
def _build_signature(self, cube, default_fill_value=False): | ||
""" | ||
Generate the signature that defines this cube. | ||
|
||
|
@@ -1625,16 +1624,18 @@ def _build_signature(self, cube, fill_value=None): | |
|
||
Kwargs: | ||
|
||
* fill_value: | ||
Promoted fill-value to use instead of the source cube | ||
fill-value. | ||
* default_fill_value: | ||
Override the cube fill value with the default fill value of None. | ||
Default is False i.e. use the provided cube.fill_value when | ||
constructing the cube signature. | ||
|
||
Returns: | ||
The cube signature. | ||
|
||
""" | ||
if fill_value is None: | ||
fill_value = cube.fill_value | ||
fill_value = cube.fill_value | ||
if default_fill_value: | ||
fill_value = None | ||
return _CubeSignature(cube.metadata, cube.shape, cube.dtype, | ||
fill_value, cube._cell_measures_and_dims) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, also applies to
_merge.py
👍