From 9f48498ca811c59a8f5312764dd456aba4da60a9 Mon Sep 17 00:00:00 2001 From: matveyvarg Date: Fri, 5 Jul 2024 17:12:41 +0200 Subject: [PATCH 1/2] Fix writable flag --- deker_server_adapters/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/deker_server_adapters/base.py b/deker_server_adapters/base.py index a62e2c7..36d19c2 100644 --- a/deker_server_adapters/base.py +++ b/deker_server_adapters/base.py @@ -263,6 +263,7 @@ def read_data( ) numpy_array = np.frombuffer(response.read(), dtype=array.dtype) # type: ignore[call-overload] + numpy_array.flags.writeable = True shape = array[bounds].shape if not shape and numpy_array.size: return numpy_array[0] From 5d2845c1aaff0dbf2e435d14806b806c47e678ca Mon Sep 17 00:00:00 2001 From: matveyvarg Date: Fri, 5 Jul 2024 17:22:34 +0200 Subject: [PATCH 2/2] fix bytearray --- deker_server_adapters/base.py | 3 +-- tests/test_cases/test_common/test_array_adapter.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/deker_server_adapters/base.py b/deker_server_adapters/base.py index 36d19c2..6608e0f 100644 --- a/deker_server_adapters/base.py +++ b/deker_server_adapters/base.py @@ -262,8 +262,7 @@ def read_data( message=f"Timeout on {self.type.name} read {array}", ) - numpy_array = np.frombuffer(response.read(), dtype=array.dtype) # type: ignore[call-overload] - numpy_array.flags.writeable = True + numpy_array = np.frombuffer(bytearray(response.read()), dtype=array.dtype) # type: ignore[call-overload] shape = array[bounds].shape if not shape and numpy_array.size: return numpy_array[0] diff --git a/tests/test_cases/test_common/test_array_adapter.py b/tests/test_cases/test_common/test_array_adapter.py index d0f8465..d69af97 100644 --- a/tests/test_cases/test_common/test_array_adapter.py +++ b/tests/test_cases/test_common/test_array_adapter.py @@ -234,3 +234,13 @@ def test_read_data_single_number( data = np.zeros(shape=(1,)) httpx_mock.add_response(content=data.tobytes(), url=re.compile(r".*array.*")) assert server_array_adapter.read_data(array, np.index_exp[0]) == data[0] + + +def test_read_data_single_number( + array: Array, httpx_mock: HTTPXMock, server_array_adapter: ServerArrayAdapter, collection: Collection, mock_status +): + data = np.zeros(shape=(1,)) + httpx_mock.add_response(content=data.tobytes(), url=re.compile(r".*array.*")) + read_data = server_array_adapter.read_data(array, np.index_exp[:]) + read_data[0] = 0 + assert read_data[0] == 0