Skip to content

Commit 7817bed

Browse files
committedFeb 28, 2024·
Tiny fixes after review
1 parent eedd251 commit 7817bed

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed
 

‎test/core/store/ref/test_store.py

+24-14
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121

2222
import glob
2323
import json
24+
import unittest
2425
from abc import ABC, abstractmethod
2526
from pathlib import Path
2627
from typing import List
27-
import unittest
2828

2929
import fsspec
30-
import numpy as np
3130
import pytest
3231
import xarray as xr
3332

@@ -91,11 +90,14 @@ def tearDownClass(cls):
9190
def assert_sst_cube_ok(self, cube: xr.Dataset):
9291
self.assertEqual({'time': 3, 'lat': 1350, 'lon': 1600}, cube.sizes)
9392
self.assertEqual({'lon', 'time', 'lat'}, set(cube.coords))
94-
self.assertEqual({'analysis_error', 'mask', 'analysed_sst', 'sea_ice_fraction'},
95-
set(cube.data_vars))
93+
self.assertEqual(
94+
{'analysis_error', 'mask', 'analysed_sst', 'sea_ice_fraction'},
95+
set(cube.data_vars))
9696
sst_ts = cube.isel(lat=0, lon=0).compute()
97-
np.testing.assert_array_equal(sst_ts.analysed_sst.values,
98-
np.array([290.02, 289.94, 289.89]))
97+
sst_data = sst_ts.analysed_sst.values
98+
self.assertAlmostEqual(290.02, sst_data[0])
99+
self.assertAlmostEqual(289.94, sst_data[1])
100+
self.assertAlmostEqual(289.89, sst_data[2])
99101

100102

101103
# noinspection PyUnresolvedReferences
@@ -129,7 +131,8 @@ def test_list_data_ids(self):
129131

130132
def test_get_data_opener_ids(self):
131133
store = self.get_store()
132-
self.assertEqual(("dataset:zarr:reference",), store.get_data_opener_ids())
134+
self.assertEqual(("dataset:zarr:reference",),
135+
store.get_data_opener_ids())
133136

134137
def test_get_data_types(self):
135138
store = self.get_store()
@@ -190,13 +193,15 @@ def test_search_data(self):
190193

191194

192195
@unittest.skipUnless(has_kerchunk, reason="kerchunk not installed")
193-
class ReferenceDataStorePathsTest(ReferenceDataStoreTestBase, unittest.TestCase):
196+
class ReferenceDataStorePathsTest(ReferenceDataStoreTestBase,
197+
unittest.TestCase):
194198
def get_store(self) -> DataStore:
195199
return new_data_store("reference", refs=self.ref_paths)
196200

197201

198202
@unittest.skipUnless(has_kerchunk, reason="kerchunk not installed")
199-
class ReferenceDataStoreDictsTest(ReferenceDataStoreTestBase, unittest.TestCase):
203+
class ReferenceDataStoreDictsTest(ReferenceDataStoreTestBase,
204+
unittest.TestCase):
200205
def get_store(self) -> DataStore:
201206
store = new_data_store("reference", refs=self.ref_paths)
202207
refs = [dict(ref_path=ref_path,
@@ -211,7 +216,8 @@ class NormalizeRefTest(unittest.TestCase):
211216
def test_normalize_str(self):
212217
self.assertEqual(
213218
('sst-cube',
214-
{'ref_path': 'https://myrefs.com/sst-cube.json', 'data_descriptor': None}),
219+
{'ref_path': 'https://myrefs.com/sst-cube.json',
220+
'data_descriptor': None}),
215221
self.normalize_ref("https://myrefs.com/sst-cube.json")
216222
)
217223

@@ -240,18 +246,22 @@ def test_normalize_dict_with_data_descriptor(self):
240246
"data_type": "dataset"
241247
}})
242248
self.assertEqual("sst-bibo", data_id)
243-
self.assertEqual("https://myrefs.com/sst-cube.json", ref_dict.get("ref_path"))
244-
self.assertIsInstance(ref_dict.get("data_descriptor"), DatasetDescriptor)
249+
self.assertEqual("https://myrefs.com/sst-cube.json",
250+
ref_dict.get("ref_path"))
251+
self.assertIsInstance(ref_dict.get("data_descriptor"),
252+
DatasetDescriptor)
245253
self.assertEqual(
246254
"sst-bibo",
247255
ref_dict.get("data_descriptor").data_id
248256
)
249257

250258
def test_errors(self):
251-
with pytest.raises(TypeError, match="item in refs must be a str or a dict"):
259+
with pytest.raises(TypeError,
260+
match="item in refs must be a str or a dict"):
252261
# noinspection PyTypeChecker
253262
self.normalize_ref(13)
254-
with pytest.raises(ValueError, match="missing key ref_path in refs item"):
263+
with pytest.raises(ValueError,
264+
match="missing key ref_path in refs item"):
255265
self.normalize_ref({})
256266
with pytest.raises(TypeError, match=("value of data_descriptor key"
257267
" in refs item must be a dict or None")):

‎xcube/core/geom.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ def get_dataset_bounds(dataset: Union[xr.Dataset, xr.DataArray],
722722

723723
# Note, x_min > x_max then we intersect with the anti-meridian
724724
x_bnds_name = get_dataset_bounds_var_name(dataset, x_name)
725-
if x_bnds_name and x_bnds_name in dataset:
725+
if x_bnds_name is not None:
726726
x_bnds_var = dataset[x_bnds_name]
727727
x1 = x_bnds_var[0, 0]
728728
x2 = x_bnds_var[0, 1]
@@ -741,7 +741,7 @@ def get_dataset_bounds(dataset: Union[xr.Dataset, xr.DataArray],
741741

742742
# Note, x-axis may be inverted
743743
y_bnds_name = get_dataset_bounds_var_name(dataset, y_name)
744-
if y_bnds_name and y_bnds_name in dataset:
744+
if y_bnds_name is not None:
745745
y_bnds_var = dataset[y_bnds_name]
746746
y1 = y_bnds_var[0, 0]
747747
y2 = y_bnds_var[0, 1]

‎xcube/core/store/fs/impl/fs.py

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
2121

22-
from xcube.util.jsonschema import JsonArraySchema
2322
from xcube.util.jsonschema import JsonBooleanSchema
2423
from xcube.util.jsonschema import JsonIntegerSchema
2524
from xcube.util.jsonschema import JsonObjectSchema

‎xcube/core/store/ref/store.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
import os
2323
import warnings
24-
from typing import Iterator, Any, Tuple, Container, Union, Dict, List, \
25-
Optional
24+
from typing import Iterator, Any, Tuple, Container, Union, Dict, List
2625

2726
import fsspec
2827
import xarray as xr

0 commit comments

Comments
 (0)
Please sign in to comment.