Numpy structured array unintuitive handling
- Lenguaje dominante
- Julia
- Estrellas
- 1.5k
- Forks
- 186
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
Hi,
Thank you for the great work on this package.
I have to deal with a [numpy structured array](https://docs.scipy.org/doc/numpy-1.15.0/user/basics.rec.html) variable that I've imported into Julia. I've called this variable `my_simulations`.
To see the different fields inside this variable, I can call `my_simulations[:dtype]` and I get
```PyObject dtype([('drugs', 'O'), ('Vms', 'O'), ('I_tots', 'O'), ('Ycs', 'O'), ('Cais', 'O'), ('Nais', 'O'), ('caSRs', 'O'), ('ts', 'O')])```.
The first element of each tuple in the list corresponds to the names of the keys (numpy calls them fields) in this variable.
In Python, you can access each key using `my_simulations['keyname']`, e.g. `my_simulations['Vms']`. I expected that in Julia you could access each key using `my_simulations["keyname"]`, e.g. `my_simulations["Vms"]`. But this doesn't work and I get the following error message
```ERROR: KeyError: key "Vms" not found```
The workaround I've found is to call `get(my_sims,"keyname")` e.g. `get(my_sims,"Vms")` which works. But the method `my_simulations["keyname"]` would be more intuitive and closer to the Python syntax.
Thank you!
My version of PyCall is v"1.18.5+".
Best,
Max
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Reproduce el comportamiento reportado con un array estructurado de NumPy importado mediante PyCall, comparando my_simulations["Vms"] con get(my_simulations,"Vms"). Inspecciona el comportamiento de indexación de objetos de PyCall y las pruebas existentes relacionadas con objetos de Python. Se considera terminado cuando la indexación mediante cadenas accede a los campos del array estructurado como se solicita, sin regresiones en la forma get, que funciona.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- julia, numpy
- Área
- data, tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100