numpy arrays read from attributes are not writable

Aperta
#53 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
numpy, python
Ambito
backend

Direzione di ricerca

Inizia con il percorso di accesso all’attributo raggiunto da f.attrs["att"] e confrontalo con il percorso di lettura del dataset usato da f["arr"][:]. Esegui la MCVE sul repository per esaminare i diversi flag degli array; il lavoro è completato quando gli array degli attributi possono essere modificati in memoria in modo coerente con gli array dei dataset e il comportamento è coperto da un test di regressione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Python
Stelle
105
Fork
29
Merge medio
2g 8h
PR unite (30g)
9

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NCAS-CMS/pyfive

Tutte le issue di NCAS-CMS/pyfive

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.