From 7e64a28b1e8814a8d6b9217ce79bb8de546e62f3 Mon Sep 17 00:00:00 2001 From: Slawomir Kolodynski Date: Wed, 26 Dec 2018 17:23:59 +0100 Subject: [PATCH] replaced deprecated f'romstring' by 'frombuffer', this fixes issue #64 --- CHANGELOG.txt | 2 ++ doc/source/conf.py | 2 +- doc/source/type-conversion.rst | 4 ++-- qpython/qreader.py | 4 ++-- qpython/qtype.py | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 1023881..fed2929 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -7,6 +7,8 @@ because of 'async' becoming a keyword in Python 3.7 - replaced DataFrame.as_matrix() method (deprecated since Pandas 0.23.0) by DataFrame.values + - replaced numpy.fromstring method (deprecated since NumPy 1.14) by + numpy.frombuffer ------------------------------------------------------------------------------ qPython 1.3.0 [2017.03.xx] diff --git a/doc/source/conf.py b/doc/source/conf.py index 95ac5d8..70eb4ec 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -29,7 +29,7 @@ def __getattr__(cls, name): # workaround for building docs without numpy import numpy -numpy.fromstring = lambda x, dtype: [None] +numpy.frombuffer = lambda x, dtype: [None] numpy.ndarray = Mock # end-of-workaround diff --git a/doc/source/type-conversion.rst b/doc/source/type-conversion.rst index 6b0b8e8..27e1688 100644 --- a/doc/source/type-conversion.rst +++ b/doc/source/type-conversion.rst @@ -370,8 +370,8 @@ Please note that q ``null`` values are defined as:: _QNULL2 = numpy.int16(-2**15) _QNULL4 = numpy.int32(-2**31) _QNULL8 = numpy.int64(-2**63) - _QNAN32 = numpy.fromstring('\x00\x00\xc0\x7f', dtype=numpy.float32)[0] - _QNAN64 = numpy.fromstring('\x00\x00\x00\x00\x00\x00\xf8\x7f', dtype=numpy.float64)[0] + _QNAN32 = numpy.frombuffer('\x00\x00\xc0\x7f', dtype=numpy.float32)[0] + _QNAN64 = numpy.frombuffer('\x00\x00\x00\x00\x00\x00\xf8\x7f', dtype=numpy.float64)[0] _QNULL_BOOL = numpy.bool_(False) _QNULL_SYM = numpy.string_('') _QNULL_GUID = uuid.UUID('00000000-0000-0000-0000-000000000000') diff --git a/qpython/qreader.py b/qpython/qreader.py index 3a602e3..2dbdf54 100644 --- a/qpython/qreader.py +++ b/qpython/qreader.py @@ -200,7 +200,7 @@ def read_data(self, message_size, is_compressed = False, **options): uncompressed_size = -8 + self._buffer.get_int() compressed_data = self._read_bytes(message_size - 12) if self._stream else self._buffer.raw(message_size - 12) - raw_data = numpy.fromstring(compressed_data, dtype = numpy.uint8) + raw_data = numpy.frombuffer(compressed_data, dtype = numpy.uint8) if uncompressed_size <= 0: raise QReaderException('Error while data decompression.') @@ -296,7 +296,7 @@ def _read_list(self, qtype): return qlist(data, qtype = qtype, adjust_dtype = False) elif conversion: raw = self._buffer.raw(length * ATOM_SIZE[qtype]) - data = numpy.fromstring(raw, dtype = conversion) + data = numpy.frombuffer(raw, dtype = conversion) if not self._is_native: data.byteswap(True) diff --git a/qpython/qtype.py b/qpython/qtype.py index 64c3aef..ee44168 100644 --- a/qpython/qtype.py +++ b/qpython/qtype.py @@ -259,8 +259,8 @@ _QNULL2 = numpy.int16(-2**15) _QNULL4 = numpy.int32(-2**31) _QNULL8 = numpy.int64(-2**63) -_QNAN32 = numpy.fromstring(b'\x00\x00\xc0\x7f', dtype=numpy.float32)[0] -_QNAN64 = numpy.fromstring(b'\x00\x00\x00\x00\x00\x00\xf8\x7f', dtype=numpy.float64)[0] +_QNAN32 = numpy.frombuffer(b'\x00\x00\xc0\x7f', dtype=numpy.float32)[0] +_QNAN64 = numpy.frombuffer(b'\x00\x00\x00\x00\x00\x00\xf8\x7f', dtype=numpy.float64)[0] _QNULL_BOOL = numpy.bool_(False) _QNULL_SYM = numpy.string_('') _QNULL_GUID = uuid.UUID('00000000-0000-0000-0000-000000000000')