From 86c00a402543428d44a6c7be5ddfbe7f53e10516 Mon Sep 17 00:00:00 2001 From: nishantharkut Date: Tue, 17 Mar 2026 11:26:52 +0530 Subject: [PATCH 1/2] fix: correct warnings.warn arguments in deprecated assign_ugrid_topology wrapper Swap the warning message and category arguments in the utils compatibility wrapper so DeprecationWarning is emitted correctly. Add stacklevel=2 so the warning points to user call sites, and add a regression test that checks warning category, message content, and caller filename. --- tests/test_utils.py | 22 ++++++++++++++++++++++ xarray_subset_grid/utils.py | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 6b64a2c..0612460 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,9 +1,11 @@ import os +import warnings import numpy as np import pytest from xarray_subset_grid.utils import ( + assign_ugrid_topology, normalize_bbox_x_coords, normalize_polygon_x_coords, ray_tracing_numpy, @@ -125,3 +127,23 @@ def test_ray_tracing_numpy(): result = ray_tracing_numpy(points[:, 0], points[:, 1], poly) assert np.array_equal(result, [False, True, False]) + + +def test_assign_ugrid_topology_warns_with_deprecation_warning(monkeypatch): + def fake_assign_ugrid_topology(*args, **kwargs): + return "ok" + + monkeypatch.setattr( + "xarray_subset_grid.grids.ugrid.assign_ugrid_topology", + fake_assign_ugrid_topology, + ) + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always") + result = assign_ugrid_topology(None) + + assert result == "ok" + assert len(caught) == 1 + assert caught[0].category is DeprecationWarning + assert "assign_grid_topology" in str(caught[0].message) + assert os.path.basename(caught[0].filename) == "test_utils.py" diff --git a/xarray_subset_grid/utils.py b/xarray_subset_grid/utils.py index e004525..c1e6f06 100644 --- a/xarray_subset_grid/utils.py +++ b/xarray_subset_grid/utils.py @@ -97,10 +97,11 @@ def ray_tracing_numpy(x, y, poly): # this placeholder for backwards compatibility for a brief period def assign_ugrid_topology(*args, **kwargs): warnings.warn( - DeprecationWarning, "The function `assign_grid_topology` has been moved to the " "`grids.ugrid` module. It will not be able to be called from " "the utils `module` in the future.", + DeprecationWarning, + stacklevel=2, ) from .grids.ugrid import assign_ugrid_topology From da740510cedd252c34fc9d3071fc2ff62ab7c373 Mon Sep 17 00:00:00 2001 From: nishantharkut Date: Tue, 17 Mar 2026 13:34:27 +0530 Subject: [PATCH 2/2] fix: address review feedback - correct function name in deprecation message Apply Copilot review suggestions: - Fix function name in warning message: change assign_grid_topology to assign_ugrid_topology (the correct function name in the repo) - Remove backticks around second occurrence of 'module' (plain English word, not code reference) - Use keyword argument category=DeprecationWarning instead of positional argument - Update test assertion to match corrected message --- tests/test_utils.py | 2 +- xarray_subset_grid/utils.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 0612460..115d9a2 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -145,5 +145,5 @@ def fake_assign_ugrid_topology(*args, **kwargs): assert result == "ok" assert len(caught) == 1 assert caught[0].category is DeprecationWarning - assert "assign_grid_topology" in str(caught[0].message) + assert "assign_ugrid_topology" in str(caught[0].message) assert os.path.basename(caught[0].filename) == "test_utils.py" diff --git a/xarray_subset_grid/utils.py b/xarray_subset_grid/utils.py index c1e6f06..1c50ea3 100644 --- a/xarray_subset_grid/utils.py +++ b/xarray_subset_grid/utils.py @@ -97,10 +97,10 @@ def ray_tracing_numpy(x, y, poly): # this placeholder for backwards compatibility for a brief period def assign_ugrid_topology(*args, **kwargs): warnings.warn( - "The function `assign_grid_topology` has been moved to the " + "The function `assign_ugrid_topology` has been moved to the " "`grids.ugrid` module. It will not be able to be called from " - "the utils `module` in the future.", - DeprecationWarning, + "the utils module in the future.", + category=DeprecationWarning, stacklevel=2, ) from .grids.ugrid import assign_ugrid_topology