Skip to content

Commit

Permalink
Fix warnings and test with locate_geoms (#96)
Browse files Browse the repository at this point in the history
* Fix test according to correct result from locate_geoms
* Resolve warnings from pandas, geopandas
* Fix for pandas 1.x
  • Loading branch information
mwtoews authored May 27, 2024
1 parent dce37b6 commit ceb06ab
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions swn/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,10 @@ def locate_geoms(
if v in missng_segnum_idx_s:
del override[k]
if override:
res.segnum.update(override)
if pd.__version__.startswith("1."):
res.segnum.update(override)
else:
res.update({"segnum": override})
res.loc[override.keys(), "method"] = "override"

# Mark empty geometries
Expand Down Expand Up @@ -1254,7 +1257,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],
Expand Down
2 changes: 1 addition & 1 deletion swn/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions swn/modflow/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ def test_locate_geoms_only_lines(coastal_geom, coastal_swn):
e = pd.DataFrame(
{
"method": "nearest",
"segnum": [3047364, 3048663, 3048249, 3049113, 3047736, 3047145, 3046736],
"segnum": [3047364, 3048663, 3048249, 3049113, 3047736, 3047145, 3046745],
"seg_ndist": [0.5954064, 0.0974058, 0.279147, 0.0, 0.684387, 0.0, 0.541026],
"dist_to_seg": [
80.25,
Expand Down
1 change: 1 addition & 0 deletions tests/test_modflow_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
]
)
Expand Down

0 comments on commit ceb06ab

Please sign in to comment.