Skip to content

Commit

Permalink
Use is to compare types
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomodeller committed Jun 28, 2024
1 parent 33b92b4 commit 47234c7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ def test_xzy_selection():
das_xzy = ds.Temperature.sel(x=348946, y=6173673, z=0)

# check for point geometry after selection
assert type(das_xzy.geometry) == mikeio.spatial.GeometryPoint3D
assert type(das_xzy.geometry) is mikeio.spatial.GeometryPoint3D
assert das_xzy.values[0] == pytest.approx(17.381)

# do the same but go one level deeper, but finding the index first
Expand Down Expand Up @@ -1301,7 +1301,7 @@ def test_layer_selection():

das_layer = ds.Temperature.sel(layers=0)
# should not be layered after selection
assert type(das_layer.geometry) == mikeio.spatial.GeometryFM2D
assert type(das_layer.geometry) is mikeio.spatial.GeometryFM2D


def test_time_selection():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ def test_layer_selection():

dss_layer = ds.sel(layers=0)
# should not be layered after selection
assert type(dss_layer.geometry) == mikeio.spatial.GeometryFM2D
assert type(dss_layer.geometry) is mikeio.spatial.GeometryFM2D


def test_time_selection():
Expand Down
16 changes: 8 additions & 8 deletions tests/test_dfsu_transect.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_transect_geometry_properties_geo(vslice_geo):
def test_transect_read(vslice):
ds = vslice.read()
assert ds.geometry._type == DfsuFileType.DfsuVerticalProfileSigmaZ
assert type(ds.geometry) == GeometryFMVerticalProfile
assert type(ds.geometry) is GeometryFMVerticalProfile
assert ds.n_items == 2
assert ds.Salinity.name == "Salinity"
assert ds.geometry.n_elements == 441
Expand All @@ -78,7 +78,7 @@ def test_transect_getitem_element(vslice):
da = vslice.read().Salinity
idx = 5
da2 = da[:, idx]
assert type(da2.geometry) == GeometryPoint3D
assert type(da2.geometry) is GeometryPoint3D
assert da2.geometry.x == da.geometry.element_coordinates[idx, 0]
assert da2.geometry.y == da.geometry.element_coordinates[idx, 1]
assert da2.geometry.z == da.geometry.element_coordinates[idx, 2]
Expand All @@ -90,7 +90,7 @@ def test_transect_isel(vslice):
da = vslice.read().Salinity
idx = 5
da2 = da.isel(element=idx)
assert type(da2.geometry) == GeometryPoint3D
assert type(da2.geometry) is GeometryPoint3D
assert da2.geometry.x == da.geometry.element_coordinates[idx, 0]
assert da2.geometry.y == da.geometry.element_coordinates[idx, 1]
assert da2.geometry.z == da.geometry.element_coordinates[idx, 2]
Expand All @@ -105,7 +105,7 @@ def test_transect_isel_multiple(vslice_geo):

ds2 = ds.isel(element=idx)
assert ds2.geometry.n_elements == 579
assert type(ds2.geometry) == GeometryFMVerticalProfile
assert type(ds2.geometry) is GeometryFMVerticalProfile
rd2 = ds2.geometry.relative_element_distance
assert rd2.max() < 15000

Expand All @@ -114,7 +114,7 @@ def test_transect_sel_time(vslice):
da = vslice.read()[0]
idx = 1
da2 = da.sel(time="1997-09-16 00:00")
assert type(da2.geometry) == GeometryFMVerticalProfile
assert type(da2.geometry) is GeometryFMVerticalProfile
assert np.all(da2.to_numpy() == da.to_numpy()[idx, :])
assert da2.time[0] == da.time[1]
assert da2.dims == ("element",)
Expand All @@ -124,7 +124,7 @@ def test_transect_sel_time(vslice):
def test_transect_sel_xyz(vslice_geo):
da = vslice_geo.read().Temperature
da2 = da.sel(x=10.8, y=55.6, z=-3)
assert type(da2.geometry) == GeometryPoint3D
assert type(da2.geometry) is GeometryPoint3D
assert da2.geometry.x == pytest.approx(10.802878)
assert da2.geometry.y == pytest.approx(55.603096)
assert da2.geometry.z == pytest.approx(-2.3)
Expand All @@ -134,13 +134,13 @@ def test_transect_sel_xyz(vslice_geo):
def test_transect_sel_layers(vslice_geo):
ds = vslice_geo.read()
ds2 = ds.sel(layers=range(-6, -1))
assert type(ds2.geometry) == GeometryFMVerticalProfile
assert type(ds2.geometry) is GeometryFMVerticalProfile


def test_transect_sel_xy(vslice_geo):
da = vslice_geo.read().Temperature
da2 = da.sel(x=10.8, y=55.6)
assert type(da2.geometry) == GeometryFMVerticalColumn
assert type(da2.geometry) is GeometryFMVerticalColumn
gx, gy, _ = da2.geometry.element_coordinates.mean(axis=0)
assert gx == pytest.approx(10.802878)
assert gy == pytest.approx(55.603096)
Expand Down

0 comments on commit 47234c7

Please sign in to comment.