Skip to content

Commit 25c1684

Browse files
authored
Merge pull request #1469 from Unidata/issue1468
Fix DeprecationWarning for assigning to numpy.ndarray.shape
2 parents 0710bf2 + 1e76c6a commit 25c1684

3 files changed

Lines changed: 5 additions & 6 deletions

File tree

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
=================================
33
* Change default encoding for stringtochar/chartostring functions from 'utf-8' to 'utf-8'/'ascii' for dtype.kind='U'/'S'
44
(issue #1464).
5+
* Fix DeprecationWarning for assigning to numpy.ndarray.shape for numpy >= 2.5.0 (issue #1468).
56

67
version 1.7.4 (tag v1.7.4rel)
78
================================

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def _populate_hdf5_info(dirstosearch, inc_dirs, libs, lib_dirs):
322322
netCDF4_libdir = os.path.join(netCDF4_dir, 'lib')
323323

324324
if sys.platform == 'win32':
325-
libs.extend(['netcdf', 'zlib'])
325+
libs.extend(['netcdf'])
326326
else:
327327
libs.extend(['netcdf', 'z'])
328328

src/netCDF4/_netCDF4.pyx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5630,7 +5630,7 @@ cannot be safely cast to variable data type""" % attname
56305630
# create a view so shape in caller is not modified (issue 90)
56315631
try: # if extra singleton dims, just reshape
56325632
data = data.view()
5633-
data.shape = tuple(datashape)
5633+
data = data.reshape(tuple(datashape))
56345634
except ValueError: # otherwise broadcast
56355635
data = numpy.broadcast_to(data, datashape)
56365636

@@ -6821,8 +6821,7 @@ and shape `a.shape + (N,)`, where N is the length of each string in a."""
68216821
if encoding in ['none','None','bytes']:
68226822
b = numpy.array(tuple(a.tobytes()),'S1')
68236823
elif encoding == 'ascii':
6824-
b = numpy.array(tuple(a.tobytes().decode(encoding)),dtype+'1')
6825-
b.shape = a.shape + (n_strlen,)
6824+
b = (numpy.array(tuple(a.tobytes().decode(encoding)),dtype+'1')).reshape(a.shape + (n_strlen,))
68266825
else:
68276826
if not a.ndim:
68286827
a = numpy.array([a])
@@ -6862,8 +6861,7 @@ returns a numpy string array with datatype `'UN'` (or `'SN'`) and shape
68626861
a = numpy.array([bs[n1:n1+slen] for n1 in range(0,len(bs),slen)],'S'+repr(slen))
68636862
else:
68646863
a = numpy.array([bs[n1:n1+slen].decode(encoding) for n1 in range(0,len(bs),slen)],'U'+repr(slen))
6865-
a.shape = b.shape[:-1]
6866-
return a
6864+
return a.reshape(b.shape[:-1])
68676865

68686866
class MFDataset(Dataset):
68696867
"""

0 commit comments

Comments
 (0)