From 34cff25b47d7ced14923dd0f3d4ad2709d041446 Mon Sep 17 00:00:00 2001 From: jlarsen-usgs Date: Wed, 5 Aug 2026 13:49:44 -0700 Subject: [PATCH 1/2] update(Raster, ModelTime): Deprecation warnings maintenance: * replace numpy .shape = with .reshape() in Raster * replace .utcfromtimestamp with fromtimestamp(timestamp, timezone.utc) in ModelTime --- flopy/discretization/modeltime.py | 5 +++-- flopy/utils/rasters.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/flopy/discretization/modeltime.py b/flopy/discretization/modeltime.py index 2056c0110..8ef7a93eb 100644 --- a/flopy/discretization/modeltime.py +++ b/flopy/discretization/modeltime.py @@ -1,6 +1,6 @@ import calendar from dataclasses import dataclass, field -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from difflib import SequenceMatcher import numpy as np @@ -479,7 +479,8 @@ def parse_datetime( elif isinstance(datetime_obj, np.datetime64): unix_time_0 = datetime(1970, 1, 1) ts = (datetime_obj - np.datetime64(unix_time_0)) / np.timedelta64(1, "s") - datetime_obj = datetime.utcfromtimestamp(ts) + datetime_obj = datetime.fromtimestamp(ts, tz=timezone.utc) + datetime_obj = datetime_obj.replace(tzinfo=None) elif isinstance(datetime_obj, pd.Timestamp): datetime_obj = datetime_obj.to_pydatetime() elif isinstance(datetime_obj, datetime): diff --git a/flopy/utils/rasters.py b/flopy/utils/rasters.py index 10489e308..caae365f1 100644 --- a/flopy/utils/rasters.py +++ b/flopy/utils/rasters.py @@ -588,7 +588,7 @@ def resample_to_grid( data = np.where(np.isnan(data), extrapolate, data) # step 4: return grid to user in shape provided - data.shape = data_shape + data = data.reshape(data_shape) # step 5: re-apply nodata values data[np.isnan(data)] = self.nodatavals[0] From bfa371d64ca048a839f30dd2120806c8f601bc86 Mon Sep 17 00:00:00 2001 From: jlarsen-usgs Date: Wed, 5 Aug 2026 14:02:33 -0700 Subject: [PATCH 2/2] maintenance `.shape =` calls replaced with `arr = arr.reshape()` * numpy will be deprecating `.shape =` reshaping, migrating to reshape convention to prevent DeprecationWarnings --- flopy/discretization/structuredgrid.py | 4 ++-- flopy/discretization/vertexgrid.py | 2 +- flopy/mf6/utils/binaryfile_utils.py | 4 ++-- flopy/mf6/utils/binarygrid_util.py | 6 +++--- flopy/mf6/utils/model_splitter.py | 2 +- flopy/plot/plotutil.py | 10 +++++----- flopy/utils/postprocessing.py | 10 +++++----- flopy/utils/zonbud.py | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/flopy/discretization/structuredgrid.py b/flopy/discretization/structuredgrid.py index 18bab69f8..7aa6bcc40 100644 --- a/flopy/discretization/structuredgrid.py +++ b/flopy/discretization/structuredgrid.py @@ -2057,8 +2057,8 @@ def from_binary_grid_file(cls, file_path, verbose=False): nlay, nrow, ncol = (grb_obj.nlay, grb_obj.nrow, grb_obj.ncol) delr, delc = grb_obj.delr, grb_obj.delc top, botm = grb_obj.top, grb_obj.bot - top.shape = (nrow, ncol) - botm.shape = (nlay, nrow, ncol) + top = top.reshape((nrow, ncol)) + botm = botm.reshape((nlay, nrow, ncol)) return cls( delc, delr, diff --git a/flopy/discretization/vertexgrid.py b/flopy/discretization/vertexgrid.py index ddb8da4b5..66f23dd57 100644 --- a/flopy/discretization/vertexgrid.py +++ b/flopy/discretization/vertexgrid.py @@ -847,7 +847,7 @@ def from_binary_grid_file(cls, file_path, verbose=False): nlay, ncpl = grb_obj.nlay, grb_obj.ncpl top = np.ravel(grb_obj.top) botm = grb_obj.bot - botm.shape = (nlay, ncpl) + botm = botm.reshape((nlay, ncpl)) vertices, cell2d = grb_obj.cell2d return cls( diff --git a/flopy/mf6/utils/binaryfile_utils.py b/flopy/mf6/utils/binaryfile_utils.py index 91bcd0abd..941ba31ab 100644 --- a/flopy/mf6/utils/binaryfile_utils.py +++ b/flopy/mf6/utils/binaryfile_utils.py @@ -375,9 +375,9 @@ def _reshape_binary_data(data, dtype=None): return data elif dtype == "V": nodes = len(data[0][0][0]) - data.shape = (time, -1, nodes) + data = data.reshape((time, -1, nodes)) elif dtype == "U": - data.shape = (time, -1) + data = data.reshape((time, -1)) else: err = "Invalid dtype flag supplied, valid are dtype='U', dtype='V'" raise Exception(err) diff --git a/flopy/mf6/utils/binarygrid_util.py b/flopy/mf6/utils/binarygrid_util.py index 88e9b565c..c74cc20f9 100644 --- a/flopy/mf6/utils/binarygrid_util.py +++ b/flopy/mf6/utils/binarygrid_util.py @@ -238,7 +238,7 @@ def _set_modelgrid(self): nlay, ncpl = self.nlay, self.ncpl vertices, cell2d = self.cell2d top = np.ravel(top) - botm.shape = (nlay, ncpl) + botm = botm.reshape((nlay, ncpl)) modelgrid = VertexGrid( vertices, cell2d, @@ -258,8 +258,8 @@ def _set_modelgrid(self): ) delr, delc = self.delr, self.delc - top.shape = (nrow, ncol) - botm.shape = (nlay, nrow, ncol) + top.reshape((nrow, ncol)) + botm = botm.reshape((nlay, nrow, ncol)) modelgrid = StructuredGrid( delc, delr, diff --git a/flopy/mf6/utils/model_splitter.py b/flopy/mf6/utils/model_splitter.py index 72bd0f3a9..8b333cb5e 100644 --- a/flopy/mf6/utils/model_splitter.py +++ b/flopy/mf6/utils/model_splitter.py @@ -833,7 +833,7 @@ def reconstruct_array(self, arrays): new_array[new_nodes] = array[old_nodes] - new_array.shape = shape + new_array = new_array.reshape(shape) return new_array def reconstruct_recarray(self, recarrays): diff --git a/flopy/plot/plotutil.py b/flopy/plot/plotutil.py index 23f6d00f3..fdce65021 100644 --- a/flopy/plot/plotutil.py +++ b/flopy/plot/plotutil.py @@ -1482,11 +1482,11 @@ def saturated_thickness(head, top, botm, laytyp, mask_values=None): head = np.copy(head) nlay, nrow, ncol = head.shape ncpl = nrow * ncol - head.shape = (nlay, ncpl) - top.shape = (ncpl,) - botm.shape = (nlay, ncpl) + head = head.reshape((nlay, ncpl)) + top = top.reshape((ncpl,)) + botm = botm.reshape((nlay, ncpl)) if laytyp.ndim == 3: - laytyp.shape = (nlay, ncpl) + laytyp = laytyp.reshape((nlay, ncpl)) else: nrow, ncol = None, None @@ -1531,7 +1531,7 @@ def saturated_thickness(head, top, botm, laytyp, mask_values=None): sat_thk = np.where(laytyp != 0, sat_thk_unconf, sat_thk_conf) if nrow is not None and ncol is not None: - sat_thk.shape = (nlay, nrow, ncol) + sat_thk = sat_thk.reshape((nlay, nrow, ncol)) return sat_thk diff --git a/flopy/utils/postprocessing.py b/flopy/utils/postprocessing.py index ec9416626..656f7d0f4 100644 --- a/flopy/utils/postprocessing.py +++ b/flopy/utils/postprocessing.py @@ -801,7 +801,7 @@ def get_specific_discharge( modelgrid = model.modelgrid if head is not None: - head.shape = modelgrid.shape + head = head.reshape(modelgrid.shape) if isinstance(vectors, (list, tuple)): classical_budget = True @@ -857,7 +857,7 @@ def get_specific_discharge( head, mask=[model.hdry, model.hnoflo] ) - saturated_thickness.shape = modelgrid.shape + saturated_thickness = saturated_thickness.reshape(modelgrid.shape) # inform modelgrid of no-flow and dry cells modelgrid = model.modelgrid @@ -927,9 +927,9 @@ def get_specific_discharge( qx[idx] = spdis["qx"] qy[idx] = spdis["qy"] qz[idx] = spdis["qz"] - qx.shape = modelgrid.shape - qy.shape = modelgrid.shape - qz.shape = modelgrid.shape + qx = qx.reshape(modelgrid.shape) + qy = qy.reshape(modelgrid.shape) + qz = qz.reshape(modelgrid.shape) # set no-flow and dry cells to NaN if head is not None and position == "centers": diff --git a/flopy/utils/zonbud.py b/flopy/utils/zonbud.py index b8dd2a8ae..ee87abb93 100644 --- a/flopy/utils/zonbud.py +++ b/flopy/utils/zonbud.py @@ -2677,7 +2677,7 @@ def _read_zb_csv2(fname, add_prefix=True, aliases=None): array = np.genfromtxt(foo, delimiter=",").T if len(array) != len(dtype): array = array[:-1] - array.shape = (len(dtype), -1) + array = array.reshape((len(dtype), -1)) data = {name[0]: list(array[ix]) for ix, name in enumerate(dtype)} data["KPER"] = list(np.array(data["KPER"]) - 1) data["KSTP"] = list(np.array(data["KSTP"]) - 1)