Skip to content

Conversation

@erikvansebille
Copy link
Member

This PR raises an error when users create a Field based on a grid with dimensions without axis. I found on multiple occasions, that without this error, the assert just below breaks:

if all(ax_dim[0] is None for ax_dim in ax_dims):
# Assuming its a 1D constant field (hence has no axes)
assert da.shape == (1, 1, 1, 1)

One example is the unit test added to this PR

Parcels/tests/test_xgrid.py

Lines 138 to 142 in 419ce76

def test_dim_without_axis():
ds = xr.Dataset({"z1d": (["depth"], [0])}, coords={"depth": [0]})
grid = XGrid.from_dataset(ds)
with pytest.raises(ValueError, match='Dimension "depth" has no axis attribute*'):
Field("z1d", ds["z1d"], grid)

Not sure though if this is the best place for this error message. Some other, previously passing tests, now fail.

@VeckoTheGecko, perhaps you could weigh in where this error would be most appropriate ?

@VeckoTheGecko
Copy link
Contributor

Not sure though if this is the best place for this error message. Some other, previously passing tests, now fail.

@VeckoTheGecko, perhaps you could weigh in where this error would be most appropriate ?

I think it would be great to have in a dedicated function - I've pushed a patch baa16c7 . Thoughts?

@erikvansebille
Copy link
Member Author

Yep, good solution, @VeckoTheGecko. I like this!

@erikvansebille erikvansebille marked this pull request as ready for review November 18, 2025 10:38
Copy link
Contributor

@VeckoTheGecko VeckoTheGecko left a comment

Choose a reason for hiding this comment

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

LGTM!

@erikvansebille erikvansebille merged commit 486c5b6 into v4-dev Nov 18, 2025
11 checks passed
@erikvansebille erikvansebille deleted the error_when_dims_have_no_axis branch November 18, 2025 10:49
@github-project-automation github-project-automation bot moved this from Backlog to Done in Parcels development Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants