Skip to content

Commit 195dc3c

Browse files
authored
Pandas and Xarray deprecations (#1374)
* Change resampling frequency from deprecated '1M' to '1ME' * Change resampling frequency from deprecated 'Q' to 'QE' * Update tests to use sizes instead of dims where appropriate * Update tests to use sizes instead of dims where appropriate
1 parent dd603dd commit 195dc3c

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

test/core/test_accessors.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ def test_resample_reduces_time_dimension(gridpath):
138138
uxds = ux.UxDataset(ds, uxgrid=ux.open_grid(gridpath("ugrid", "outCSne30", "outCSne30.ug")))
139139

140140
# Test monthly resampling reduces from 365 days to 12 months
141-
monthly = uxds.resample(time="1M").mean()
141+
monthly = uxds.resample(time="1ME").mean()
142142
assert "time" in monthly.dims, "time dimension missing after resample"
143-
assert monthly.dims["time"] < uxds.dims["time"], "time dimension not reduced"
144-
assert monthly.dims["time"] <= 12, "monthly resampling should give 12 or fewer time points"
143+
assert monthly.sizes["time"] < uxds.sizes["time"], "time dimension not reduced"
144+
assert monthly.sizes["time"] <= 12, "monthly resampling should give 12 or fewer time points"
145145

146146

147147
def test_resample_with_cftime(gridpath):
@@ -166,10 +166,10 @@ def test_resample_with_cftime(gridpath):
166166
uxds = ux.UxDataset(ds, uxgrid=ux.open_grid(gridpath("ugrid", "outCSne30", "outCSne30.ug")))
167167

168168
# Test that quarterly resampling works with cftime
169-
quarterly = uxds.resample(time="Q").mean()
169+
quarterly = uxds.resample(time="QE").mean()
170170
assert hasattr(quarterly, "uxgrid"), "uxgrid not preserved with cftime resampling"
171171
assert "time" in quarterly.dims, "time dimension missing after cftime resample"
172-
assert quarterly.dims["time"] < uxds.dims["time"], "time dimension not reduced with cftime"
172+
assert quarterly.sizes["time"] < uxds.sizes["time"], "time dimension not reduced with cftime"
173173

174174

175175
def test_rolling_preserves_uxgrid(gridpath):
@@ -237,7 +237,7 @@ def test_coarsen_preserves_uxgrid(gridpath):
237237

238238
# Test that coarsen reduces dimension correctly
239239
assert len(da_result.time) == 8, "coarsen by 3 should reduce 24 points to 8"
240-
assert ds_result.dims["time"] == 8, "coarsen should reduce time dimension"
240+
assert ds_result.sizes["time"] == 8, "coarsen should reduce time dimension"
241241

242242

243243
def test_weighted_preserves_uxgrid(gridpath, datasetpath):
@@ -251,7 +251,7 @@ def test_weighted_preserves_uxgrid(gridpath, datasetpath):
251251
gridpath("ugrid", "outCSne30", "outCSne30.ug"),
252252
datasetpath("ugrid", "outCSne30", "outCSne30_var2.nc")
253253
)
254-
n_face = uxds_base.dims["n_face"]
254+
n_face = uxds_base.sizes["n_face"]
255255

256256
# Create data with time and face dimensions
257257
temp_data = np.random.rand(10, n_face)

test/core/test_inheritance.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def ds():
1616

1717
uxds["fc"] = uxds["fc"].assign_coords(face_id=("n_face", np.arange(uxgrid.n_face)))
1818
uxds["nc"] = uxds["nc"].assign_coords(node_id=("n_node", np.arange(uxgrid.n_node)))
19-
uxds["t"] = uxds["t"].assign_coords(time_id=("time", np.arange(uxds.dims["time"])))
19+
uxds["t"] = uxds["t"].assign_coords(time_id=("time", np.arange(uxds.sizes["time"])))
2020

2121
return uxds
2222

@@ -109,7 +109,7 @@ def test_groupby(self, ds):
109109
assert hasattr(grouped, 'uxgrid')
110110

111111
def test_assign_coords(self, ds):
112-
n = ds.dims['n_face']
112+
n = ds.sizes['n_face']
113113
new_coord = xr.DataArray(np.arange(n) * 10, dims=['n_face'])
114114
out = ds.assign_coords(scaled_id=new_coord)
115115
assert isinstance(out, ux.UxDataset)
@@ -121,7 +121,7 @@ def test_expand_dims(self, ds):
121121
out = ds.expand_dims({'member': 1})
122122
assert isinstance(out, ux.UxDataset)
123123
assert hasattr(out, 'uxgrid') and out.uxgrid is ds.uxgrid
124-
assert 'member' in out.dims and out.dims['member'] == 1
124+
assert 'member' in out.dims and out.sizes['member'] == 1
125125
assert 'member' in out['t'].dims and out['t'].sizes['member'] == 1
126126

127127
def test_method_chaining(self, ds):
@@ -147,7 +147,7 @@ def test_stack_unstack(self, ds):
147147
assert unstacked['fc'].shape == ds_fc['fc'].shape
148148

149149
def test_sortby(self, ds):
150-
n = ds.dims['n_face']
150+
n = ds.sizes['n_face']
151151
ds_fc = ds[['fc']].assign_coords(reverse_id=('n_face', np.arange(n)[::-1]))
152152
out = ds_fc.sortby('reverse_id')
153153
assert isinstance(out, ux.UxDataset)

0 commit comments

Comments
 (0)