Skip to content

Commit

Permalink
Keep coords deprecation warning (#383)
Browse files Browse the repository at this point in the history
* throw deprecation warning

* test to check warning is thrown

* whatsnew

Co-authored-by: Julius Busecke <julius@ldeo.columbia.edu>
  • Loading branch information
TomNicholas and jbusecke authored Dec 3, 2021
1 parent 742be12 commit 8fdf2bf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ Internal Changes
By `Tom Nicholas <https://github.com/TomNicholas>`_.[*]_


Deprecations
~~~~~~~~~~~~~

- The `keep_coords` kwarg is now deprecated, and will be removed in the next version. (:issue:`382`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.[*]_



v0.5.2 (2021/5/27)
-------------------

Expand Down
8 changes: 8 additions & 0 deletions xgcm/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,14 @@ def _wrap_and_replace_coords(self, da, data_new, position_to, keep_coords=False)
Take the base coords from da, the data from data_new, and return
a new DataArray with a coordinate on position_to.
"""

if not keep_coords:
warnings.warn(
"The keep_coords keyword argument is being deprecated - in future it will be removed "
"entirely, and the behaviour will always be that currently given by keep_coords=True.",
category=DeprecationWarning,
)

position_from, old_dim = self._get_position_name(da)
try:
new_dim = self.coords[position_to]
Expand Down
9 changes: 9 additions & 0 deletions xgcm/test/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,15 @@ def test_keep_coords(funcname, gridtype):
assert set(result.coords) == set(base_coords + augmented_coords)


def test_keep_coords_deprecation():
ds, coords, metrics = datasets_grid_metric("B")
ds = ds.assign_coords(yt_bis=ds["yt"], xt_bis=ds["xt"])
grid = Grid(ds, coords=coords, metrics=metrics)
for axis_name in grid.axes.keys():
with pytest.warns(DeprecationWarning):
grid.diff(ds.tracer, axis_name, keep_coords=False)


def test_boundary_kwarg_same_as_grid_constructor_kwarg():
ds = datasets["2d_left"]
grid1 = Grid(ds, periodic=False)
Expand Down

0 comments on commit 8fdf2bf

Please sign in to comment.