h2oai / h2oai/wave

Handle np.nan in data()

Open
#447 1 comment 0 reactions 0 assignees View on GitHub
feature plot
Dominant language
Python
Stars
4.3k
Forks
371
Avg merge
26d 1h
Merged PRs (30d)
1

Description

#### Is your feature request related to a problem? Please describe
When plotting data from pandas or numpy arrays, missing values are of the type `np.nan` which is not useable by json. When trying to use a numpy object with missing values into a wave `data` object we get the error `Out of range float values are not JSON compliant` which is hard to debug.

#### Describe the solution you'd like
Ideally `data` would replace `np.nan` with `None` so that missing values are still shown in the plots and handled automatically.

#### Describe alternatives you've considered
Require the wave developer to handle this conversion and include further documentation to help

#### Additional context
Plots 1 and 2 work, plot 3 fails with `Out of range float values are not JSON compliant`
```python
from h2o_wave import Q, ui, app, main, data
import numpy as np

@app('/')
async def serve(q: Q):
plot1 = ui.visualization(
ui.plot(marks=[ui.mark(type='point', x=f'=col1', y=f'=col1', color='red', shape='circle', size=10)]),
data(fields=['col1'], rows=[[1], [2], [3]], pack=True),
height='20%', width='90%',
)

plot2 = ui.visualization(
ui.plot(marks=[ui.mark(type='point', x=f'=col1', y=f'=col1', color='red', shape='circle', size=10)]),
data(fields=['col1'], rows=[[None], [2], [3]], pack=True),
height='20%', width='90%',
)

plot3 = ui.visualization(
ui.plot(marks=[ui.mark(type='point', x=f'=col1', y=f'=col1', color='red', shape='circle', size=10)]),
data(fields=['col1'], rows=[[np.nan], [2], [3]], pack=True),
height='20%', width='90%',
)

q.page['plots'] = ui.form_card(
box='1 1 5 -1',
items=[plot1, plot2, plot3]
)

await q.page.save()
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.