From c08e279c2af7746d79315bcfb06583193b5d0927 Mon Sep 17 00:00:00 2001 From: Ryan Murray <74630349+rywm-dhi@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:30:47 +0100 Subject: [PATCH] Remove deprecations for ResultReach --- .../geopandas_reaches_converter_segmented.py | 2 +- mikeio1d/result_network/result_gridpoint.py | 2 +- mikeio1d/result_network/result_reach.py | 21 ------------------- tests/test_geometry.py | 18 ++++++++-------- tests/test_geopandas.py | 6 ++++-- tests/test_res1d_network.py | 8 ------- 6 files changed, 15 insertions(+), 42 deletions(-) diff --git a/mikeio1d/geometry/geopandas/geopandas_reaches_converter_segmented.py b/mikeio1d/geometry/geopandas/geopandas_reaches_converter_segmented.py index 930ba960..118cd497 100644 --- a/mikeio1d/geometry/geopandas/geopandas_reaches_converter_segmented.py +++ b/mikeio1d/geometry/geopandas/geopandas_reaches_converter_segmented.py @@ -43,7 +43,7 @@ def _create_dataframe_data_dict(self, reaches: ResultReaches) -> dict[str, tuple "geometry": [], } for reach in reaches.values(): - for res1d_reach in reach.reaches: + for res1d_reach in reach.res1d_reaches: data["group"].append(TimeSeriesIdGroup.REACH) data["name"].append(reach.name) data["tag"].append(TimeSeriesId.create_reach_span_tag(res1d_reach)) diff --git a/mikeio1d/result_network/result_gridpoint.py b/mikeio1d/result_network/result_gridpoint.py index 681e875c..55c42443 100644 --- a/mikeio1d/result_network/result_gridpoint.py +++ b/mikeio1d/result_network/result_gridpoint.py @@ -121,7 +121,7 @@ def get_m1d_dataset(self, m1d_dataitem: IDataItem = None) -> IRes1DGridPoint: IRes1DDataSet object associated with ResultGridPoint. """ - return self.reach + return self.res1d_reach def get_query(self, data_item: IDataItem) -> QueryDataReach: """Get a QueryDataReach for given data item.""" diff --git a/mikeio1d/result_network/result_reach.py b/mikeio1d/result_network/result_reach.py index deb4d698..bb539dec 100644 --- a/mikeio1d/result_network/result_reach.py +++ b/mikeio1d/result_network/result_reach.py @@ -60,17 +60,6 @@ def __repr__(self) -> str: """Return a string representation of ResultReach.""" return f"" - def __getattr__(self, name: str): - """Get attributes, warnings of deprecated attributes.""" - # TODO: Remove this in 1.0.0 - if hasattr(self.res1d_reaches[0], name): - warnings.warn( - f"Accessing IRes1DReach attribute {name} like this is deprecated. Use static attributes instead, or .reaches[0].{name}." - ) - return getattr(self.res1d_reaches[0], name) - else: - object.__getattribute__(self, name) - def __getitem__(self, key: str | int) -> ResultGridPoint: """Get a ResultGridPoint object by chainage.""" if isinstance(key, int): @@ -215,16 +204,6 @@ def interpolate_reach_critical_level(self, chainage: float) -> float: """ return self._creator._interpolate_reach_critical_level(chainage) - # region Deprecated methods and attributes of ResultReach. - - @property - def reaches(self) -> List[IRes1DReach]: - """List of IRes1DReach corresponding to this result location.""" - warnings.warn("The 'reaches' property is deprecated. Use 'res1d_reaches' instead.") - return self.res1d_reaches - - # endregion - class ResultReachCreator(ResultLocationCreator): """Helper class for creating ResultReach. diff --git a/tests/test_geometry.py b/tests/test_geometry.py index db67858e..788a35a7 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -81,28 +81,28 @@ def test_reach_chainage_from_geometric_distance(self, reach_geometry): assert reach_geometry.chainage_from_geometric_distance((1**2 + 1**2) ** 0.5) == 10 def test_from_res1d_reaches(self, river_reach): - g = ReachGeometry.from_res1d_reaches(river_reach.reaches) - expected_n_gridpoints = sum([reach.GridPoints.Count for reach in river_reach.reaches]) + g = ReachGeometry.from_res1d_reaches(river_reach.res1d_reaches) + expected_n_gridpoints = sum([reach.GridPoints.Count for reach in river_reach.res1d_reaches]) assert len(g.gridpoints) == expected_n_gridpoints - expected_n_digipoints = sum([reach.DigiPoints.Count for reach in river_reach.reaches]) + expected_n_digipoints = sum([reach.DigiPoints.Count for reach in river_reach.res1d_reaches]) assert len(g.digipoints) == expected_n_digipoints assert len(g.points) == expected_n_gridpoints + expected_n_digipoints - gp_start = river_reach.reaches[0].GridPoints[0] + gp_start = river_reach.res1d_reaches[0].GridPoints[0] assert g.gridpoints[0].x == pytest.approx(gp_start.X) assert g.gridpoints[0].y == pytest.approx(gp_start.Y) assert g.gridpoints[0].z == pytest.approx(gp_start.Z) assert g.gridpoints[0].chainage == pytest.approx(gp_start.Chainage) - dp_start = river_reach.reaches[0].DigiPoints[0] + dp_start = river_reach.res1d_reaches[0].DigiPoints[0] assert g.digipoints[0].x == pytest.approx(dp_start.X) assert g.digipoints[0].y == pytest.approx(dp_start.Y) assert g.digipoints[0].z == pytest.approx(dp_start.Z) assert g.digipoints[0].chainage == pytest.approx(dp_start.M) - gp_end = list(river_reach.reaches[-1].GridPoints)[-1] + gp_end = list(river_reach.res1d_reaches[-1].GridPoints)[-1] assert g.gridpoints[-1].x == pytest.approx(gp_end.X) assert g.gridpoints[-1].y == pytest.approx(gp_end.Y) assert g.gridpoints[-1].z == pytest.approx(gp_end.Z) assert g.gridpoints[-1].chainage == pytest.approx(gp_end.Chainage) - dp_end = list(river_reach.reaches[-1].DigiPoints)[-1] + dp_end = list(river_reach.res1d_reaches[-1].DigiPoints)[-1] assert g.digipoints[-1].x == pytest.approx(dp_end.X) assert g.digipoints[-1].y == pytest.approx(dp_end.Y) assert g.digipoints[-1].z == pytest.approx(dp_end.Z) @@ -114,7 +114,7 @@ def test_from_res1d_reaches(self, river_reach): assert g.length == pytest.approx(2024.2276598819008) def test_reaches_point_interpolation_matches_mikeplus(self, river_reach): - g = ReachGeometry.from_res1d_reaches(river_reach.reaches) + g = ReachGeometry.from_res1d_reaches(river_reach.res1d_reaches) shape = g.to_shapely() # from MIKE+ chainage_points expected_coords = { @@ -156,7 +156,7 @@ def test_geometry_from_nodes_runs(many_nodes): def test_geometry_from_reaches_runs(many_reaches): for reach in many_reaches: - g = ReachGeometry.from_res1d_reaches(reach.reaches).to_shapely() + g = ReachGeometry.from_res1d_reaches(reach.res1d_reaches).to_shapely() assert isinstance(g, shapely.LineString) diff --git a/tests/test_geopandas.py b/tests/test_geopandas.py index 2ecad813..c904bb88 100644 --- a/tests/test_geopandas.py +++ b/tests/test_geopandas.py @@ -105,11 +105,13 @@ def test_geopandas_reaches_converter_segmented(res1d_river_network): converter = GeoPandasReachesConverterSegmented() gdf = converter.to_geopandas(res1d_river_network.reaches) assert isinstance(gdf, GeoDataFrame) - number_of_segments = sum(len(reach.reaches) for reach in res1d_river_network.reaches.values()) + number_of_segments = sum( + len(reach.res1d_reaches) for reach in res1d_river_network.reaches.values() + ) assert len(gdf) == number_of_segments assert ["group", "name", "tag", "geometry"] == list(gdf.columns) sample_reach_name = "river" - sample_reach_segments = res1d_river_network.reaches[sample_reach_name].reaches + sample_reach_segments = res1d_river_network.reaches[sample_reach_name].res1d_reaches sample_reach = sample_reach_segments[len(sample_reach_segments) // 2] sample_reach_tag = TimeSeriesId.create_reach_span_tag(sample_reach) geometry = gdf.query(f"name == '{sample_reach_name}' and tag == '{sample_reach_tag}'").iloc[0][ diff --git a/tests/test_res1d_network.py b/tests/test_res1d_network.py index fe69767a..a2cf16d7 100644 --- a/tests/test_res1d_network.py +++ b/tests/test_res1d_network.py @@ -449,11 +449,3 @@ def test_structure_reach_maintains_backweards_compatibility(res1d_network): with pytest.warns(UserWarning): assert structures.s_119w1.structure_id == structures.s_119w1.id - - -def test_reaches_dict_access_maintains_backwards_compatibility(res1d_network, res1d_river_network): - with pytest.warns(UserWarning): - # Indexing reaches could return a single dotnet reach - reach = res1d_network.reaches["100l1"] - assert reach.Name == "100l1" - assert reach.Length == pytest.approx(47.6827148432828)