assert_array_equal does not compare NaNs as numbers when dtype is object
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 32.8k
- Fork
- 12.8k
- Merge medio
- 1g 7h
- PR unite (30g)
- 197
Descrizione
OS: macOS Sierra (10.12.5)
Python version: 2.7.12
numpy version: 1.13.0
I notice that numpy.testing.assert_array_equal should compare NaNs as numbers unlike elsewhere in numpy, which makes sense to me. I verify this with the following test:
>>> import numpy.testing as npt
>>> import numpy as np
>>> a = np.array([1, 2, np.nan])
>>> npt.assert_array_equal(a, a)
However, this does not work with arrays that have dtype object:
>>> b = np.array([1, 2, 'a', np.nan], dtype=object)
>>> npt.assert_array_equal(b, b)
AssertionError:
Arrays are not equal
(mismatch 25.0%)
x: array([1, 2, 'a', nan], dtype=object)
y: array([1, 2, 'a', nan], dtype=object)
Is this the desired behaviour? The only workaround in my case is to cast the array as dtype str.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Parti da numpy.testing.assert_array_equal e riproduci i due esempi dell’issue, confrontando array di dtype regular e object-dtype contenenti NaN. Segui il percorso di confronto degli array di oggetti e aggiungi un test di regressione che mostri il comportamento di confronto previsto per NaN, quindi esegui i test NumPy Testing pertinenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- testing-qa
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 43/100