Skip to content

Commit

Permalink
fix dims without coords (#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 authored May 2, 2024
1 parent 2721d33 commit f7f2d1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit f7f2d1c

Please sign in to comment.