Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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)
==============================
Expand Down
12 changes: 6 additions & 6 deletions netCDF4/_netCDF4.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <char**>PyMem_Malloc(sizeof(char*) * att_len)
Expand Down Expand Up @@ -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

Expand All @@ -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))
Expand Down