Skip to content

Conversation

@aldenks
Copy link
Member

@aldenks aldenks commented Oct 21, 2025

The array encoding fill_value is not properly read back when opening a zarr.

ds = xr.open_zarr(store_factory.primary_store())

result = validation.check_for_expected_shards(primary_store, ds)
assert result.passed, result.message
Copy link
Contributor

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]

Copy link
Member Author

@aldenks aldenks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved! Thank you

Comment on lines 172 to 174
@pytest.mark.filterwarnings(
"ignore:This process .* is multi-threaded, use of fork.* may lead to deadlocks in the child"
)
Copy link
Member Author

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

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.
Copy link
Member Author

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

Comment on lines 188 to 215
# 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
)
Copy link
Member Author

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

aldenks and others added 2 commits October 27, 2025 09:07
Ensure fill_value present in encoding and set write_empty_chunks to
True.

Update fill value for NDVI and SWANN to 0.0
Copy link
Member Author

@aldenks aldenks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved latest changes

@mosegontar mosegontar merged commit 9cf8313 into main Oct 27, 2025
5 checks passed
@mosegontar mosegontar deleted the nan-fill-round-trip branch October 27, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants