reveal_type shows the same, but one of the objects generates an error
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Merge medio
- 1g 18h
- PR unite (30g)
- 54
Descrizione
How come mypy warns that astype doesn't expect the variable dtypes, while it is OK to explicitly type it there?
from typing import Dict, Union
import pandas as pd
dat = pd.DataFrame(data={"A": [1], "B": [4]})
dtypes = {"A":float, "B":"int64"}
dat[[*dtypes]].astype(dtypes) # mypy error
dat[[*dtypes]].astype({"A":float, "B":"int64"}) # no mypy error
def myf()->Dict[str, Union[str,type]]: # this is fine
return {"A":float, "B":"int64"}
dat[[*dtypes]].astype(myf()) # this is also fine
by calling from typing_extensions import reveal_type, it shows that both the var and the explicit definition has builtins.dict[builtins.str, builtins.object]
While the function return's type is "builtins.dict[builtins.str, Union[builtins.str, builtins.type]]"
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
Inizia con il reproducer Python fornito e confronta i tipi inferiti per la variabile, il dizionario inline e il valore restituito dalla funzione nella chiamata a pandas astype. Determina se le diverse diagnostiche sono intenzionali; il lavoro è concluso quando viene spiegata la causa o viene risolta la diagnostica incoerente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100