Skip to content

Commit e0e0422

Browse files
committed
o repo hygiene plotting: hvplot in tests; zonal_average delegates to zonal_mean (xr.DataArray)
1 parent 49d0364 commit e0e0422

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

test/test_plot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,19 @@ def test_dataarray_methods(gridpath, datasetpath):
7676
# plot.scatter() is an xarray method
7777
assert hasattr(uxds.plot, 'scatter')
7878

79+
import hvplot.xarray # registers .hvplot accessor
80+
7981
def test_line(gridpath):
8082
mesh_path = gridpath("mpas", "QU", "oQU480.231010.nc")
8183
uxds = ux.open_dataset(mesh_path, mesh_path)
82-
_plot_line = uxds['bottomDepth'].zonal_average().plot.line()
84+
_plot_line = uxds['bottomDepth'].zonal_average().hvplot.line()
8385
assert isinstance(_plot_line, hv.Curve)
8486

8587
def test_scatter(gridpath):
8688
mesh_path = gridpath("mpas", "QU", "oQU480.231010.nc")
8789
uxds = ux.open_dataset(mesh_path, mesh_path)
88-
_plot_line = uxds['bottomDepth'].zonal_average().plot.scatter()
89-
assert isinstance(_plot_line, hv.Scatter)
90+
_plot_scatter = uxds['bottomDepth'].zonal_average().hvplot.scatter()
91+
assert isinstance(_plot_scatter, hv.Scatter)
9092

9193

9294

uxarray/core/dataarray.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -643,20 +643,8 @@ def zonal_mean(self, lat=(-90, 90, 10), conservative: bool = False, **kwargs):
643643
)
644644

645645
def zonal_average(self, lat=(-90, 90, 10), conservative: bool = False, **kwargs):
646-
"""Zonal average convenience returning an object with the plotting accessor.
647-
648-
Returns a UxDataArray for compatibility with plotting tests while delegating
649-
computation to zonal_mean.
650-
"""
651-
da = self.zonal_mean(lat=lat, conservative=conservative, **kwargs)
652-
return UxDataArray(
653-
da.data,
654-
uxgrid=self.uxgrid,
655-
dims=list(da.dims),
656-
coords=da.coords,
657-
name=da.name,
658-
attrs=da.attrs,
659-
)
646+
"""Alias of zonal_mean; prefer `zonal_mean` for primary API."""
647+
return self.zonal_mean(lat=lat, conservative=conservative, **kwargs)
660648

661649
def weighted_mean(self, weights=None):
662650
"""Computes a weighted mean.

0 commit comments

Comments
 (0)