From 2c518fc19bce3179964dfd4156a1c5b84881ee61 Mon Sep 17 00:00:00 2001 From: jswhit2 Date: Mon, 16 Feb 2026 08:53:12 -0700 Subject: [PATCH 1/2] Fix DeprecationWarning for assigning to numpy.ndarray.shape (issue #1468) --- Changelog | 1 + src/netCDF4/_netCDF4.pyx | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 55bc6b0db..a1de04ffa 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,7 @@ ================================= * Change default encoding for stringtochar/chartostring functions from 'utf-8' to 'utf-8'/'ascii' for dtype.kind='U'/'S' (issue #1464). + * Fix DeprecationWarning for assigning to numpy.ndarray.shape for numpy >= 2.5.0 (issue #1468). version 1.7.4 (tag v1.7.4rel) ================================ diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 2f5a133c9..3470d7a4c 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -5630,7 +5630,7 @@ cannot be safely cast to variable data type""" % attname # create a view so shape in caller is not modified (issue 90) try: # if extra singleton dims, just reshape data = data.view() - data.shape = tuple(datashape) + data = data.reshape(tuple(datashape)) except ValueError: # otherwise broadcast data = numpy.broadcast_to(data, datashape) @@ -6821,8 +6821,7 @@ and shape `a.shape + (N,)`, where N is the length of each string in a.""" if encoding in ['none','None','bytes']: b = numpy.array(tuple(a.tobytes()),'S1') elif encoding == 'ascii': - b = numpy.array(tuple(a.tobytes().decode(encoding)),dtype+'1') - b.shape = a.shape + (n_strlen,) + b = (numpy.array(tuple(a.tobytes().decode(encoding)),dtype+'1')).reshape(a.shape + (n_strlen,)) else: if not a.ndim: a = numpy.array([a]) @@ -6862,8 +6861,7 @@ returns a numpy string array with datatype `'UN'` (or `'SN'`) and shape a = numpy.array([bs[n1:n1+slen] for n1 in range(0,len(bs),slen)],'S'+repr(slen)) else: a = numpy.array([bs[n1:n1+slen].decode(encoding) for n1 in range(0,len(bs),slen)],'U'+repr(slen)) - a.shape = b.shape[:-1] - return a + return a.reshape(b.shape[:-1]) class MFDataset(Dataset): """ From 1e76c6a141772a7df0b76565e504b0bfcf51d0fb Mon Sep 17 00:00:00 2001 From: jswhit2 Date: Mon, 16 Feb 2026 10:44:50 -0700 Subject: [PATCH 2/2] try windows build without zlib --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c3b934606..8c10999ea 100644 --- a/setup.py +++ b/setup.py @@ -322,7 +322,7 @@ def _populate_hdf5_info(dirstosearch, inc_dirs, libs, lib_dirs): netCDF4_libdir = os.path.join(netCDF4_dir, 'lib') if sys.platform == 'win32': - libs.extend(['netcdf', 'zlib']) + libs.extend(['netcdf']) else: libs.extend(['netcdf', 'z'])