From 9b3faba372577add49d1e061ef9861c3d7f2f55a Mon Sep 17 00:00:00 2001 From: Amir MOHAMMADI <amir.mohammadi@idiap.ch> Date: Thu, 18 Jun 2020 16:24:23 +0200 Subject: [PATCH] Fixes a few warnings and depracations --- beat/backend/python/baseformat.py | 4 ++-- beat/backend/python/data.py | 3 ++- beat/backend/python/loader.py | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/beat/backend/python/baseformat.py b/beat/backend/python/baseformat.py index 1a6777d..5daaa78 100644 --- a/beat/backend/python/baseformat.py +++ b/beat/backend/python/baseformat.py @@ -358,8 +358,8 @@ def unpack_array(shape, dtype, fd): # N.B.: this bit of code is optimized to reduce memory usage data_format = ENDIANNESS + dtype.str[1:] count = numpy.prod(shape_) - to_read = numpy.asscalar(dtype.itemsize*count) - a = numpy.fromstring(fd.read(to_read), dtype=data_format, count=count) + to_read = int(dtype.itemsize * count) + a = numpy.frombuffer(fd.read(to_read), dtype=data_format, count=count) return a.reshape(shape_) elif issubclass(dtype, str): # it is a string diff --git a/beat/backend/python/data.py b/beat/backend/python/data.py index 80f7547..207d3ba 100644 --- a/beat/backend/python/data.py +++ b/beat/backend/python/data.py @@ -411,7 +411,8 @@ class CachedDataSource(DataSource): # list of start/end indices to check that there are contiguous indices = [] for f_data, f_chck in zip(data_filenames, checksum_filenames): - expected_chksum = open(f_chck, "rt").read().strip() + with open(f_chck, "rt") as f: + expected_chksum = f.read().strip() current_chksum = hashFileContents(f_data) if expected_chksum != current_chksum: raise IOError( diff --git a/beat/backend/python/loader.py b/beat/backend/python/loader.py index 6e85f13..831b187 100644 --- a/beat/backend/python/loader.py +++ b/beat/backend/python/loader.py @@ -82,7 +82,8 @@ def load_module(name, path, uses): retval.__dict__[k] = load_module(k, v['path'], v['uses']) # execute the module code on the context of previously import modules - exec(compile(open(path, "rb").read(), path, 'exec'), retval.__dict__) + with open(path, "rb") as f: + exec(compile(f.read(), path, 'exec'), retval.__dict__) return retval -- GitLab