From f7f2d1ce25ada8ad6e3927f94451c37448b7b6f8 Mon Sep 17 00:00:00 2001 From: Andrew <15331990+ahuang11@users.noreply.github.com> Date: Thu, 2 May 2024 11:28:25 -0700 Subject: [PATCH] fix dims without coords (#1334) --- hvplot/tests/testui.py | 7 +++++++ hvplot/ui.py | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/hvplot/tests/testui.py b/hvplot/tests/testui.py index 0c93d471d..035fe09d8 100644 --- a/hvplot/tests/testui.py +++ b/hvplot/tests/testui.py @@ -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 @@ -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() diff --git a/hvplot/ui.py b/hvplot/ui.py index c2e750e07..ee6f260b0 100644 --- a/hvplot/ui.py +++ b/hvplot/ui.py @@ -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: