From f89a8c78c334b99a5012acd93847016c36afc5d1 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Wed, 10 Apr 2024 21:54:31 +1200 Subject: [PATCH] Resolve warnings from pandas, geopandas --- swn/core.py | 4 ++-- swn/file.py | 2 +- swn/modflow/_base.py | 4 ++-- tests/test_modflow_base.py | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/swn/core.py b/swn/core.py index 27cab0e..6a34b8e 100644 --- a/swn/core.py +++ b/swn/core.py @@ -1092,7 +1092,7 @@ def locate_geoms( if v in missng_segnum_idx_s: del override[k] if override: - res.segnum.update(override) + res.update({"segnum": override}) res.loc[override.keys(), "method"] = "override" # Mark empty geometries @@ -1254,7 +1254,7 @@ def find_downstream_in_min_stream_order(segnum): from shapely.ops import nearest_points with ignore_shapely_warnings_for_object_array(): - res.geometry.loc[sel] = res.loc[sel].apply( + res.loc[sel, "geometry"] = res.loc[sel].apply( lambda f: nearest_points( self.segments.geometry[f.segnum], f.geometry )[1], diff --git a/swn/file.py b/swn/file.py index 73c8fe7..d86524f 100644 --- a/swn/file.py +++ b/swn/file.py @@ -359,7 +359,7 @@ def write_formatted_frame(df, fname, index=True, comment_header=True): for icol, name in enumerate(df.columns): # add single quotes around items with space chars try: - sel = df[name].str.contains(" ").fillna(False) + sel = df[name].str.contains(" ").astype(bool) except AttributeError: continue na = df[name].isna() diff --git a/swn/modflow/_base.py b/swn/modflow/_base.py index ba0b6e3..5538cf4 100644 --- a/swn/modflow/_base.py +++ b/swn/modflow/_base.py @@ -361,7 +361,7 @@ def model(self, model): # Build stress period DataFrame from modflow model stress_df = pd.DataFrame({"perlen": perlen}) - stress_df["duration"] = pd.TimedeltaIndex(perlen, modeltime.time_units) + stress_df["duration"] = pd.to_timedelta(perlen, modeltime.time_units) end_time = stress_df["duration"].cumsum() stress_df["start_time"] = end_time - stress_df["duration"] stress_df["end_time"] = end_time @@ -376,10 +376,10 @@ def model(self, model): self_crs = getattr(self, "crs", None) modelgrid_crs = None epsg = modelgrid.epsg - proj4_str = modelgrid.proj4 if epsg is not None: segments_crs, modelgrid_crs, same = compare_crs(self_crs, epsg) else: + proj4_str = modelgrid.proj4 segments_crs, modelgrid_crs, same = compare_crs(self_crs, proj4_str) if segments_crs is not None and modelgrid_crs is not None and not same: self.logger.warning( diff --git a/tests/test_modflow_base.py b/tests/test_modflow_base.py index 268c42a..2958a0e 100644 --- a/tests/test_modflow_base.py +++ b/tests/test_modflow_base.py @@ -1502,6 +1502,7 @@ def test_get_location_frame_reach_info_coastal(caplog, coastal_swn, coastal_poin geopandas.GeoSeries( [Point(1810531, 5869152), Point(1806822.5, 5869173.5)], index=pd.Index([11, 12], name="id"), + crs=coastal_points.crs, ), ] )