-
Notifications
You must be signed in to change notification settings - Fork 4
Fix fill value round trip [xarray?] bug #294
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
Conversation
| ds = xr.open_zarr(store_factory.primary_store()) | ||
|
|
||
| result = validation.check_for_expected_shards(primary_store, ds) | ||
| assert result.passed, result.message |
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.
With write_empty_chunks=False, we get:
FAILED tests/common/region_job_test.py::test_region_job_empty_chunk_writing[nan] - AssertionError: ['var0', 'var1', 'var2', 'var3'] are missing expected shards: {"var0": ["1/0/0"], "var1": ["1/0/0"], "var2": ["1/0/0"], "var3": [...
FAILED tests/common/region_job_test.py::test_region_job_empty_chunk_writing[0.0] - AssertionError: ['var0', 'var1', 'var2', 'var3'] are missing expected shards: {"var0": ["1/0/0"], "var1": ["1/0/0"], "var2": ["1/0/0"], "var3": [...
Results (15.59s):
10 passed
2 failed
- tests/common/region_job_test.py:175 test_region_job_empty_chunk_writing[nan]
- tests/common/region_job_test.py:175 test_region_job_empty_chunk_writing[0.0]
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.
Approved! Thank you
tests/common/region_job_test.py
Outdated
| @pytest.mark.filterwarnings( | ||
| "ignore:This process .* is multi-threaded, use of fork.* may lead to deadlocks in the child" | ||
| ) |
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.
We can remove this now. we use spawn
tests/common/template_config_test.py
Outdated
| all changes to the dataset's TemplateConfig are reflected in the on-disk Zarr template. | ||
| Also ensure that the get_template() -> write_metadata() round trip produces exactly | ||
| the same zarr.json as already exists on disk. |
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.
And finally check that the fill value we get in the case of a missing shard matches the template
tests/common/template_config_test.py
Outdated
| # 2. Ensure that get_template() -> write_metadata() round trips without any changes | ||
|
|
||
| # Compute an end_time to pass to get_template() | ||
| dim_coords = template_config.dimension_coordinates() | ||
| append_dim_coords = dim_coords[template_config.append_dim] | ||
| end_time = append_dim_coords[-1] + pd.Timedelta(milliseconds=1) | ||
|
|
||
| template_ds = template_config.get_template(end_time) | ||
|
|
||
| test_write_metadata_path = tmp_path / "write_metadata_test.zarr" | ||
| template_utils.write_metadata( | ||
| template_ds, | ||
| test_write_metadata_path, | ||
| ) | ||
| with open(test_write_metadata_path / "zarr.json") as f: | ||
| written_template = json.load(f) | ||
|
|
||
| assert existing_template == written_template | ||
|
|
||
| # 3. Ensure that the value we get when reading from an area that has not been written | ||
| # to matches the fill value in template_config encodings | ||
| # Coords are written by write_metadata() so we do expect them to be filled and don't test that here | ||
| ds = xr.open_zarr(test_write_metadata_path, chunks=None) | ||
| for var in template_config.data_vars: | ||
| var_da = ds[var.name] | ||
| np.testing.assert_array_equal( | ||
| var_da.isel(dict.fromkeys(var_da.dims, 0)).values, var.encoding.fill_value | ||
| ) |
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.
lets break this test into 3 separate tests
18f4cee to
da4f4ba
Compare
Ensure fill_value present in encoding and set write_empty_chunks to True. Update fill value for NDVI and SWANN to 0.0
da4f4ba to
379c107
Compare
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.
approved latest changes
The array encoding fill_value is not properly read back when opening a zarr.