numpy arrays read from attributes are not writable
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start with the attribute access path reached by f.attrs["att"] and compare it with the dataset read path used by f["arr"][:]. Run the MCVE against the repository to inspect the differing array flags; done means attribute arrays can be modified in memory consistently with dataset arrays and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Description
I'm trying to wrap my head around the following issue. Arrays read from Datasets are created with numpy.memmap with "copyonwrite" flag set. So these numpy arrays can be changed in memory but not in the file. This is not true for arrays read from attributes. There we get back a numpy.ndarray with the writable-flag set to FALSE. An MCVE is attached below.
I was already looking where the flag might be set and why, but didn't come far. Any hints much appreciated.
MCVE:
import numpy as np
import h5py
import pyfive
with h5py.File("test.h5", mode="w") as f:
f.attrs["att"] = np.arange(10)
f["arr"] = np.arange(10)
with pyfive.File("test.h5") as f:
# dataset
arr = f["arr"][:]
print(type(arr))
print(arr.flags)
print(arr.base)
arr += 1
print(arr)
# attribute
att = f.attrs["att"]
print(type(att))
print(att.flags)
print(att.base)
att += 1
print(att)
<class 'numpy.memmap'>
C_CONTIGUOUS : True
F_CONTIGUOUS : True
OWNDATA : False
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False
[0 1 2 3 4 5 6 7 8 9]
[ 1 2 3 4 5 6 7 8 9 10]
<class 'numpy.ndarray'>
C_CONTIGUOUS : True
F_CONTIGUOUS : True
OWNDATA : False
WRITEABLE : False
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False
[0 1 2 3 4 5 6 7 8 9]
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [23], in <cell line: 9>()
20 print(att.flags)
21 print(att.base)
---> 22 att += 1
23 print(att)
ValueError: output array is read-only
- Dominant language
- Python
- Stars
- 105
- Forks
- 29
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 9
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NCAS-CMS/pyfive
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
further optimisationPossibly taken @bnlawrence claimed this 47 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 18/100
Maintainers usually reply within 1 day
-
pyfive and hdf5>=2Openinstallation
Difficulty 4/5 3-5 days Newbie friendliness 25/100
NCAS-CMS/pyfive#279 · 2 comments ·
Maintainers usually reply within 1 day
-
VDS datasets silently return NoneMay be free again @bnlawrence claimed this 48 days ago, and no pull request is open. Openbug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
NCAS-CMS/pyfive#275 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
difference in check_dtype for vlen compared to h5pyMay be free again @davidhassell claimed this 152 days ago, and no pull request is open. Openquestion
NCAS-CMS/pyfive#228 · 13 comments · 2 assignees ·
Maintainers usually reply within 1 day
Similar issues
-
area: ci enhancement perceived difficulty: 1
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Nitjsefnie-Harness-Commons/daedalus#1826 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
vllm-project/vllm-sail#398 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
DiamondLightSource/sm-bluesky#476 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
jenkinsci/user-guide-ai-chatbot-plugin#132 ·
Maintainers usually reply within 6 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100