Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix deprecation warnings in tests #340

Merged
merged 5 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clouddrift/adapters/gdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def rowsize(index: int, **kwargs) -> int:
decode_times=False,
concat_characters=False,
decode_coords=False,
).dims["obs"]
).sizes["obs"]
except Exception as e:
print(
f"Error processing {os.path.join(kwargs['tmp_path'], kwargs['filename_pattern'].format(id=index))}"
Expand Down
2 changes: 1 addition & 1 deletion clouddrift/adapters/gdp1h.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
warnings.warn(f"Variable {var} not found in upstream data; skipping.")

# new variables
ds["ids"] = (["traj", "obs"], [np.repeat(ds.ID.values, ds.dims["obs"])])
ds["ids"] = (["traj", "obs"], [np.repeat(ds.ID.values, ds.sizes["obs"])])

Check warning on line 222 in clouddrift/adapters/gdp1h.py

View check run for this annotation

Codecov / codecov/patch

clouddrift/adapters/gdp1h.py#L222

Added line #L222 was not covered by tests
ds["drogue_status"] = (
["traj", "obs"],
[gdp.drogue_presence(ds.drogue_lost_date.data, ds.time.data[0])],
Expand Down
2 changes: 1 addition & 1 deletion clouddrift/adapters/gdp6h.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
warnings.warn(f"Variable {var} not found in upstream data; skipping.")

# new variables
ds["ids"] = (["traj", "obs"], [np.repeat(ds.ID.values, ds.dims["obs"])])
ds["ids"] = (["traj", "obs"], [np.repeat(ds.ID.values, ds.sizes["obs"])])

Check warning on line 195 in clouddrift/adapters/gdp6h.py

View check run for this annotation

Codecov / codecov/patch

clouddrift/adapters/gdp6h.py#L195

Added line #L195 was not covered by tests
ds["drogue_status"] = (
["traj", "obs"],
[gdp.drogue_presence(ds.drogue_lost_date.data, ds.time.data[0])],
Expand Down
4 changes: 2 additions & 2 deletions clouddrift/ragged.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,10 @@ def subset(
If one of the variable in a criterion is not found in the Dataset
"""
mask_traj = xr.DataArray(
data=np.ones(ds.dims[traj_dim_name], dtype="bool"), dims=[traj_dim_name]
data=np.ones(ds.sizes[traj_dim_name], dtype="bool"), dims=[traj_dim_name]
)
mask_obs = xr.DataArray(
data=np.ones(ds.dims[obs_dim_name], dtype="bool"), dims=[obs_dim_name]
data=np.ones(ds.sizes[obs_dim_name], dtype="bool"), dims=[obs_dim_name]
)

for key in criteria.keys():
Expand Down
10 changes: 5 additions & 5 deletions clouddrift/raggedarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def from_files(
rowsize_func = (
rowsize_func
if rowsize_func
else lambda i, **kwargs: preprocess_func(i, **kwargs).dims["obs"]
else lambda i, **kwargs: preprocess_func(i, **kwargs).sizes["obs"]
)
rowsize = cls.number_of_observations(rowsize_func, indices, **kwargs)
coords, metadata, data = cls.allocate(
Expand Down Expand Up @@ -197,16 +197,16 @@ def from_xarray(cls, ds: xr.Dataset, dim_traj: str = "traj", dim_obs: str = "obs
attrs_variables[var] = ds[var].attrs

for var in ds.data_vars.keys():
if len(ds[var]) == ds.dims[dim_traj]:
if len(ds[var]) == ds.sizes[dim_traj]:
metadata[var] = ds[var].data
elif len(ds[var]) == ds.dims[dim_obs]:
elif len(ds[var]) == ds.sizes[dim_obs]:
data[var] = ds[var].data
else:
warnings.warn(
f"""
Variable '{var}' has unknown dimension size of
{len(ds[var])}, which is not traj={ds.dims[dim_traj]} or
obs={ds.dims[dim_obs]}; skipping.
{len(ds[var])}, which is not traj={ds.sizes[dim_traj]} or
obs={ds.sizes[dim_obs]}; skipping.
"""
)
attrs_variables[var] = ds[var].attrs
Expand Down
7 changes: 6 additions & 1 deletion clouddrift/sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,12 @@ def cartesian_to_spherical(
y /= R
z /= R

lon = recast_lon180(np.rad2deg(np.imag(np.log((x + 1j * y)))))
with np.errstate(divide="ignore"):
lon = np.where(
np.logical_and(x == 0, y == 0),
0,
recast_lon180(np.rad2deg(np.imag(np.log((x + 1j * y))))),
)
lat = np.rad2deg(np.arcsin(z))

return lon, lat
Expand Down
16 changes: 8 additions & 8 deletions clouddrift/wavelet.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def morse_wavelet_transform(
)
wtx = wtx_p, wtx_n

elif ~complex:
elif not complex:
# real case
wtx = wavelet_transform(x, wavelet, boundary=boundary, time_axis=time_axis)

Expand Down Expand Up @@ -583,12 +583,12 @@ def morse_freq(
--------
:func:`morse_wavelet`, :func:`morse_amplitude`
"""
# add test for type and shape in case of ndarray?
fm = np.where(
beta == 0,
np.log(2) ** (1 / gamma),
np.exp((1 / gamma) * (np.log(beta) - np.log(gamma))),
)
with np.errstate(divide="ignore"): # ignore warning when beta=0
fm = np.where(
beta == 0,
np.log(2) ** (1 / gamma),
np.exp((1 / gamma) * (np.log(beta) - np.log(gamma))),
)

fe = (
1
Expand Down Expand Up @@ -682,7 +682,7 @@ def morse_logspace_freq(
low_ = np.max(np.append(low, lowset[1]))

r = 1 + 1 / (density * width)
m = np.floor(np.log10(high_ / low_) / np.log10(r))
m = np.floor(np.log10(high_ / low_) / np.log10(r)).astype(int)[0]
radian_frequency = high_ * np.ones(int(m + 1)) / r ** np.arange(0, m + 1)

return radian_frequency
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ contiguous 1-dimensional array in memory.

Let's look at the dataset dimensions:

>>> ds.dims
>>> ds.sizes
Frozen({'traj': 17324, 'obs': 165754333})

The ``traj`` dimension has 17324 elements, which is the number of individual
Expand Down
2 changes: 1 addition & 1 deletion tests/datasets_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_glad_opens(self):

def test_glad_dims_coords(self):
ds = datasets.glad()
self.assertTrue(len(ds.dims) == 2)
self.assertTrue(len(ds.sizes) == 2)
self.assertTrue("obs" in ds.dims)
self.assertTrue("traj" in ds.dims)
self.assertTrue(len(ds.coords) == 2)
Expand Down
2 changes: 1 addition & 1 deletion tests/ragged_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def test_combine(self):

def test_empty(self):
ds_sub = subset(self.ds, {"ID": 3, "lon": (-180, 0)})
self.assertTrue(ds_sub.dims == {})
self.assertTrue(ds_sub.sizes == {})

def test_unknown_var(self):
with self.assertRaises(ValueError):
Expand Down