Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explorer; fix dims without coords crash #1334

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions hvplot/tests/testui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
from textwrap import dedent

import numpy as np
import holoviews as hv
import pandas as pd
import hvplot.pandas
Expand Down Expand Up @@ -381,3 +382,9 @@ def test_explorer_code_opts():
color_levels=3,
)
```""")


def test_explorer_xarray_multi_var_extra_dims_no_coord():
ds = xr.tutorial.open_dataset('air_temperature')
ds['lat_bnds'] = (('bnds', 'lat'), np.vstack([ds['lat'], ds['lat']]))
assert ds.hvplot.explorer()
5 changes: 5 additions & 0 deletions hvplot/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,11 @@ def __init__(self, ds, **params):
ds = ds[data_vars[0]]
var_name_suffix = f"['{data_vars[0]}']"
else:
missing_dims = set(ds.dims) - set(ds.coords)
if missing_dims:
# fixes https://github.com/holoviz/hvplot/issues/1272
for dim in missing_dims:
ds.coords[dim] = np.arange(len(ds[dim]))
ds = ds.to_array('variable').transpose(..., 'variable')
var_name_suffix = ".to_array('variable').transpose(..., 'variable')"
if 'kind' not in params:
Expand Down
Loading