plotly / plotly/plotly.py

Plotly Express constructor: in wide mode, lists passed to `x` and `y` params are mutated

Aperta
#4,117 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug P3
Lingua principale
Python
Stelle
18.8k
Fork
2.8k
Merge medio
16h 26m
PR unite (30g)
21

Descrizione

When either the x or y parameters to the Plotly Express constructor are passed lists of values, they are mutated such that values are converted to string.

Expected behaviour: Plotly Express should not mutate objects supplied as arguments by the user.

Minimal example (tested on Plotly 5.13.1 and master branch):

from random import randrange
import pandas as pd
import plotly.express as px

cols, rows = list(range(3)), list(range(10))
print(cols)
df = pd.DataFrame({col: [randrange(100) for _row in rows] for col in cols})
px.bar(df, y=cols, barmode="group")
print(cols)

Before the px.bar() call, cols has the value [1, 2, 3] and afterwards it is ["1", "2", "3"]. The same behaviour occurs for the x param and also when using other plotting functions than pxbar() (I tried px.histogram()).

I did some poking around, and can see that in the function build_dataframe in plotly/express/_core.py, the some of the fields in the user supplied args have copies made (which would fix this issue), but that is only applied to args found in the array_attrables list, which is ["dimensions", "custom_data", "hover_data", "path", "wide_variable"], which does not include x and y.

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia da plotly/express/_core.py e leggi build_dataframe, in particolare come array_attrables controlla la copia degli argomenti forniti dall’utente. Riproduci l’esempio minimo con liste x o y in modalità wide, quindi verifica che le liste originali mantengano i propri valori e non vengano convertite in stringhe dopo la chiamata al costruttore.

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

Valutazione

Stack tecnologico
pandas, python
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.