Skip to content

Commit a123e69

Browse files
authored
Merge pull request pandas-dev#492 from dimosped/frombuffer_hotfix
Revert to using back fromstring instead of frombuffer
2 parents e4a3f78 + c2e2a49 commit a123e69

File tree

8 files changed

+30
-11
lines changed

8 files changed

+30
-11
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Changelog
22

3+
### 1.58
4+
* Bugfix: #491 roll back the use of frombuffer to fromstring, fixes the read-only ndarray issue
5+
36
### 1.57
47
* Feature: #206 String support for tickstore
58
* Bugfix: #486 improve mongo_retry robustness with failures for version store write/append

arctic/serialization/numpy_arrays.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ def objify(self, doc, columns=None):
139139

140140
for col in cols:
141141
d = decompress(doc[DATA][doc[METADATA][LENGTHS][col][0]: doc[METADATA][LENGTHS][col][1] + 1])
142-
d = np.frombuffer(d, doc[METADATA][DTYPE][col])
142+
d = np.fromstring(d, doc[METADATA][DTYPE][col])
143143

144144
if MASK in doc[METADATA] and col in doc[METADATA][MASK]:
145145
mask_data = decompress(doc[METADATA][MASK][col])
146-
mask = np.frombuffer(mask_data, 'bool')
146+
mask = np.fromstring(mask_data, 'bool')
147147
d = ma.masked_array(d, mask)
148148
data[col] = d
149149

arctic/store/_ndarray_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def _do_read(self, collection, version, symbol, index_range=None):
200200
symbol, version['version'], segment_count, i + 1, collection.database.name + '.' + collection.name))
201201

202202
dtype = self._dtype(version['dtype'], version.get('dtype_metadata', {}))
203-
rtn = np.frombuffer(data, dtype=dtype).reshape(version.get('shape', (-1)))
203+
rtn = np.fromstring(data, dtype=dtype).reshape(version.get('shape', (-1)))
204204
return rtn
205205

206206
def _promote_types(self, dtype, dtype_str):

arctic/store/_pandas_ndarray_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _segment_index(self, recarr, existing_index, start, new_segments):
5151
dtype=INDEX_DTYPE)
5252
# append to existing index if exists
5353
if existing_index:
54-
existing_index_arr = np.frombuffer(decompress(existing_index), dtype=INDEX_DTYPE)
54+
existing_index_arr = np.fromstring(decompress(existing_index), dtype=INDEX_DTYPE)
5555
if start > 0:
5656
existing_index_arr = existing_index_arr[existing_index_arr['index'] < start]
5757
index = np.concatenate((existing_index_arr, index))
@@ -74,7 +74,7 @@ def _index_range(self, version, symbol, date_range=None, **kwargs):
7474
with the date_range. As the segment index is (id -> last datetime)
7575
we need to take care in choosing the correct chunks. """
7676
if date_range and 'segment_index' in version:
77-
index = np.frombuffer(decompress(version['segment_index']), dtype=INDEX_DTYPE)
77+
index = np.fromstring(decompress(version['segment_index']), dtype=INDEX_DTYPE)
7878
dtcol = self._datetime64_index(index)
7979
if dtcol and len(index):
8080
dts = index[dtcol]

arctic/tickstore/tickstore.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def _read_bucket(self, doc, column_set, column_dtypes, include_symbol, include_i
435435
rtn = {}
436436
if doc[VERSION] != 3:
437437
raise ArcticException("Unhandled document version: %s" % doc[VERSION])
438-
rtn[INDEX] = np.cumsum(np.frombuffer(decompress(doc[INDEX]), dtype='uint64'))
438+
rtn[INDEX] = np.cumsum(np.fromstring(decompress(doc[INDEX]), dtype='uint64'))
439439
doc_length = len(rtn[INDEX])
440440
column_set.update(doc[COLUMNS].keys())
441441

@@ -444,7 +444,7 @@ def _read_bucket(self, doc, column_set, column_dtypes, include_symbol, include_i
444444
for c in column_set:
445445
try:
446446
coldata = doc[COLUMNS][c]
447-
mask = np.frombuffer(decompress(coldata[ROWMASK]), dtype='uint8')
447+
mask = np.fromstring(decompress(coldata[ROWMASK]), dtype='uint8')
448448
union_mask = union_mask | mask
449449
except KeyError:
450450
rtn[c] = None
@@ -460,10 +460,10 @@ def _read_bucket(self, doc, column_set, column_dtypes, include_symbol, include_i
460460
try:
461461
coldata = doc[COLUMNS][c]
462462
dtype = np.dtype(coldata[DTYPE])
463-
values = np.frombuffer(decompress(coldata[DATA]), dtype=dtype)
463+
values = np.fromstring(decompress(coldata[DATA]), dtype=dtype)
464464
self._set_or_promote_dtype(column_dtypes, c, dtype)
465465
rtn[c] = self._empty(rtn_length, dtype=column_dtypes[c])
466-
rowmask = np.unpackbits(np.frombuffer(decompress(coldata[ROWMASK]),
466+
rowmask = np.unpackbits(np.fromstring(decompress(coldata[ROWMASK]),
467467
dtype='uint8'))[:doc_length].astype('bool')
468468
rowmask = rowmask[union_mask]
469469
rtn[c][rowmask] = values

tests/integration/store/test_ndarray_store.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ def test_save_read_large_ndarray(library):
124124
assert np.all(ndarr == saved_arr)
125125

126126

127+
def test_mutable_ndarray(library):
128+
dtype = np.dtype([('abc', 'int64')])
129+
ndarr = np.arange(32).view(dtype=dtype)
130+
ndarr.setflags(write=True)
131+
library.write('MYARR', ndarr)
132+
saved_arr = library.read('MYARR').data
133+
assert saved_arr.flags['WRITEABLE']
134+
135+
127136
@pytest.mark.xfail(reason="delete_version not safe with append...")
128137
def test_delete_version_shouldnt_break_read(library):
129138
data = np.arange(30)

tests/integration/store/test_pandas_store.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,3 +899,10 @@ def test_read_write_multiindex_store_keeps_timezone(library):
899899
assert list(library.read('spam').data.index[0]) == row0[:-1]
900900
assert list(library.read('spam').data.index[1]) == row1[:-1]
901901

902+
903+
def test_mutable_df(library):
904+
s = DataFrame(data=[1, 2, 3], index=[4, 5, 6])
905+
s.__array__().setflags(write=True)
906+
library.write('pandas', s)
907+
read_s = library.read('pandas')
908+
assert read_s.data.__array__().flags['WRITEABLE']

tests/integration/test_arctic_multithreading.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def my_auth_hook(host, app_name, database_name):
4242
AUTH_COUNT += 1
4343

4444

45-
@pytest.mark.timeout(300)
45+
@pytest.mark.timeout(600)
4646
def test_multiprocessing_safety(mongo_host, library_name):
4747
# Create/initialize library at the parent process, then spawn children, and start them aligned in time
4848
total_processes = 64
@@ -70,7 +70,7 @@ def test_multiprocessing_safety(mongo_host, library_name):
7070
assert isinstance(MY_ARCTIC.get_library(library_name), VersionStore)
7171

7272

73-
@pytest.mark.timeout(300)
73+
@pytest.mark.timeout(600)
7474
def test_multiprocessing_safety_parent_children_race(mongo_host, library_name):
7575
# Create Arctic and directly fork/start children (no wait)
7676
total_iterations = 12

0 commit comments

Comments
 (0)