From b2f8d7e73c0df7e334f4280c7e206ec3684f499d Mon Sep 17 00:00:00 2001 From: James Hiebert Date: Fri, 3 Jul 2020 10:26:10 -0700 Subject: [PATCH 1/2] Replaces use of numpy's tostring() with tobytes() numpy has deprecated the use of array.array.tostring() in favor of tobytes https://github.com/numpy/numpy/pull/15867 This patch replaces all (6) such uses in this package. --- netCDF4/_netCDF4.pyx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/netCDF4/_netCDF4.pyx b/netCDF4/_netCDF4.pyx index c1b98823e..c1c828a24 100644 --- a/netCDF4/_netCDF4.pyx +++ b/netCDF4/_netCDF4.pyx @@ -1455,10 +1455,10 @@ cdef _get_att(grp, int varid, name, encoding='utf-8'): if name == '_FillValue' and python3: # make sure _FillValue for character arrays is a byte on python 3 # (issue 271). - pstring = value_arr.tostring() + pstring = value_arr.tobytes() else: pstring =\ - value_arr.tostring().decode(encoding,errors='replace').replace('\x00','') + value_arr.tobytes().decode(encoding,errors='replace').replace('\x00','') return pstring elif att_type == NC_STRING: values = PyMem_Malloc(sizeof(char*) * att_len) @@ -6133,9 +6133,9 @@ and shape `a.shape + (N,)`, where N is the length of each string in a.""" if dtype not in ["S","U"]: raise ValueError("type must string or unicode ('S' or 'U')") if encoding in ['none','None','bytes']: - b = numpy.array(tuple(a.tostring()),'S1') + b = numpy.array(tuple(a.tobytes()),'S1') else: - b = numpy.array(tuple(a.tostring().decode(encoding)),dtype+'1') + b = numpy.array(tuple(a.tobytes().decode(encoding)),dtype+'1') b.shape = a.shape + (a.itemsize,) return b @@ -6159,9 +6159,9 @@ returns a numpy string array with datatype `'UN'` (or `'SN'`) and shape if dtype not in ["S","U"]: raise ValueError("type must be string or unicode ('S' or 'U')") if encoding in ['none','None','bytes']: - bs = b.tostring() + bs = b.tobytes() else: - bs = b.tostring().decode(encoding) + bs = b.tobytes().decode(encoding) slen = int(b.shape[-1]) if encoding in ['none','None','bytes']: a = numpy.array([bs[n1:n1+slen] for n1 in range(0,len(bs),slen)],'S'+repr(slen)) From f5fc6864bde3b16e30fa3c5f222690eefb8d5727 Mon Sep 17 00:00:00 2001 From: James Hiebert Date: Mon, 6 Jul 2020 09:06:35 -0700 Subject: [PATCH 2/2] Adds Changelog entry --- Changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog b/Changelog index 9182e15fb..24036f832 100644 --- a/Changelog +++ b/Changelog @@ -9,6 +9,8 @@ * check size on valid_range instead of using len (issue #1013). * add `set_chunk_cache/get_chunk_cache` module functions to reset the default chunk cache sizes before opening a Dataset (issue #1018). + * replace use of numpy's deprecated tostring() method with tobytes() + (issue #1023). version 1.5.3 (tag v1.5.3rel) ==============================