AttributeError: 'DataFrame' object has no attribute 'data_vars'

When displaying a multi-band stack of geotiffs (stacked via gdal VRT) I get random non-display of certain bands when selecting the band with the selection widget. For some stacks my visualization does not even start and shows this error message right away. Here is an example:

<xarray.DataArray (band: 35, y: 5490, x: 5490)>
dask.array<rechunk-merge, shape=(35, 5490, 5490), dtype=uint16, chunksize=(1, 2745, 2745), chunktype=numpy.ndarray>
Coordinates:
  * band     (band) <U30 'RCM1_3M13_20211122_014956_HH' ... 'RCM3_SCLNB_20220...
  * y        (y) float64 5.5e+06 5.5e+06 5.5e+06 ... 5.39e+06 5.39e+06 5.39e+06
  * x        (x) float64 5e+05 5e+05 5e+05 ... 6.097e+05 6.098e+05 6.098e+05
Attributes:
    transform:   (20.0, 0.0, 499980.0, 0.0, -20.0, 5500020.0)
    crs:         +init=epsg:32610
    res:         (20.0, 20.0)
    is_tiled:    1
    nodatavals:  (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,...
    scales:      (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,...
    offsets:     (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,...

hvp=da.hvplot.image(x='x',y='y',rasterize=True,cmap='gray',geo=True,crs='epsg:32610',\
                      frame_width=600,clim=(1500,8000),data_aspect=1,tiles='ESRI').redim.nodata(value=0)
hvp

BTW, I confirmed that the second band is valid by displaying with da.isel(band=2).hvplot.image(...). I get a valid display

Traceback (most recent call last):
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/plotting/util.py", line 277, in get_plot_frame
return map_obj[key]
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1341, in __getitem__
val = self._execute_callback(*tuple_key)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1110, in _execute_callback
retval = self.callback(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 714, in __call__
ret = self.callable(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/util/__init__.py", line 1043, in dynamic_operation
key, obj = resolve(key, kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/util/__init__.py", line 1032, in resolve
return key, map_obj[key]
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1341, in __getitem__
val = self._execute_callback(*tuple_key)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1110, in _execute_callback
retval = self.callback(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 714, in __call__
ret = self.callable(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/util/__init__.py", line 1043, in dynamic_operation
key, obj = resolve(key, kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/util/__init__.py", line 1032, in resolve
return key, map_obj[key]
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1341, in __getitem__
val = self._execute_callback(*tuple_key)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1110, in _execute_callback
retval = self.callback(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 714, in __call__
ret = self.callable(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/util/__init__.py", line 1043, in dynamic_operation
key, obj = resolve(key, kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/util/__init__.py", line 1032, in resolve
return key, map_obj[key]
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1341, in __getitem__
val = self._execute_callback(*tuple_key)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1110, in _execute_callback
retval = self.callback(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 714, in __call__
ret = self.callable(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/overlay.py", line 31, in dynamic_mul
element = other[args]
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1341, in __getitem__
val = self._execute_callback(*tuple_key)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1110, in _execute_callback
retval = self.callback(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 714, in __call__
ret = self.callable(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/util/__init__.py", line 1043, in dynamic_operation
key, obj = resolve(key, kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/util/__init__.py", line 1032, in resolve
return key, map_obj[key]
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1341, in __getitem__
val = self._execute_callback(*tuple_key)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 1110, in _execute_callback
retval = self.callback(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/core/spaces.py", line 714, in __call__
ret = self.callable(*args, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/util/__init__.py", line 1044, in dynamic_operation
return apply(obj, *key, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/util/__init__.py", line 1036, in apply
processed = self._process(element, key, kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/holoviews/util/__init__.py", line 1020, in _process
return self.p.operation(element, **kwargs)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/hvplot/converter.py", line 1089, in method_wrapper
el = method(x, y, data=ds.data)
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/hvplot/converter.py", line 1850, in image
z = list(data.data_vars)[0]
File "/home/conda/store/37bfe1afb9e3793e884fa64cb97836969a3412fb14480d75ab11c5f6ce51668a-seppo/lib/python3.8/site-packages/pandas/core/generic.py", line 5487, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'data_vars'

From the error message it looks like something is being converted to a Pandas DataFrame and then treated like it’s an Xarray Dataset. That doesn’t make much sense, so I’d suspect there is some other problem earlier that sends it down this weird code path. Hard to debug that without a small reproducible, runnable example.

I figured this out: The issue was that I had duplicates in the band names. Once I made those unique, the plotting worked fine. Maybe the error message can reflect that.

2 Likes

Nice to see that you could figure out the root cause of this problem! :+1: Btw why were you getting duplicate band names? Is that inherent to the dataset or a result of some processing?

I thing it’d be anyway nice to open an issue for this, if you find the time to do so :slight_smile: