Skip to content

Update _validate_against_pure_literal to fail on Xarray objects#2527

Merged
VeckoTheGecko merged 3 commits intoParcels-code:mainfrom
VeckoTheGecko:test-typing
Mar 2, 2026
Merged

Update _validate_against_pure_literal to fail on Xarray objects#2527
VeckoTheGecko merged 3 commits intoParcels-code:mainfrom
VeckoTheGecko:test-typing

Conversation

@VeckoTheGecko
Copy link
Contributor

Due to a bug in xarray (pydata/xarray#11209) type guarding with value in (....) wasn't working as expected.

As an xarray dataset is never a value in a Literal[...] typing statement - I have updated our typeguarding clause to error if its an xarray dataset.

Also cleaned out the test_typing.py and _typing.py modules
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this file as well into the v4 testsuite

Comment on lines +42 to +46
def _is_xarray_object(obj): # with no imports
try:
return "xarray.core" in obj.__module__
except AttributeError:
return False
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here we avoid importing xarray (otherwise we risk circular imports)

raise ValueError(msg)


# Assertion functions to clean user input
Copy link
Contributor Author

@VeckoTheGecko VeckoTheGecko Mar 2, 2026

Choose a reason for hiding this comment

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

assert_valid_interp_method and assert_valid_gridindexingtype unused in v4

@VeckoTheGecko VeckoTheGecko changed the title Update _validate_against_pure_literal Update _validate_against_pure_literal to skip Xarray objects Mar 2, 2026
@VeckoTheGecko VeckoTheGecko changed the title Update _validate_against_pure_literal to skip Xarray objects Update _validate_against_pure_literal to fail on Xarray objects Mar 2, 2026
Copy link
Member

@erikvansebille erikvansebille left a comment

Choose a reason for hiding this comment

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

Looks good; one comment below

@VeckoTheGecko VeckoTheGecko merged commit b7d6de8 into Parcels-code:main Mar 2, 2026
10 of 12 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Parcels development Mar 2, 2026
@VeckoTheGecko VeckoTheGecko deleted the test-typing branch March 2, 2026 16:44
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.

2 participants