# Buggy code
def decode(self, variable, name=None):
    dims, data, attrs, encoding = unpack_for_decoding(variable)

    if "scale_factor" in attrs or "add_offset" in attrs:
        scale_factor = pop_to(attrs, encoding, "scale_factor", name=name)
        add_offset = pop_to(attrs, encoding, "add_offset", name=name)
        dtype = _choose_float_dtype(data.dtype, "add_offset" in attrs)
        transform = partial(
            _scale_offset_decoding,
            scale_factor=scale_factor,
            add_offset=add_offset,
            dtype=dtype,
        )
        data = lazy_elemwise_func(data, transform, dtype)

    return Variable(dims, data, attrs, encoding)


# Traceback (ValueError)
Traceback (most recent call last):
File "mwe93.py", line 4, in <module>
ds["Rad"][400, 300].load()
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/xarray/core/dataarray.py", line 808, in load
ds = self._to_temp_dataset().load(**kwargs)
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/xarray/core/dataset.py", line 662, in load
v.load()
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/xarray/core/variable.py", line 439, in load
self._data = np.asarray(self._data)
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/numpy/core/_asarray.py", line 83, in asarray
return array(a, dtype, copy=False, order=order)
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/xarray/core/indexing.py", line 685, in __array__
self._ensure_cached()
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/xarray/core/indexing.py", line 682, in _ensure_cached
self.array = NumpyIndexingAdapter(np.asarray(self.array))
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/numpy/core/_asarray.py", line 83, in asarray
return array(a, dtype, copy=False, order=order)
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/xarray/core/indexing.py", line 655, in __array__
return np.asarray(self.array, dtype=dtype)
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/numpy/core/_asarray.py", line 83, in asarray
return array(a, dtype, copy=False, order=order)
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/xarray/core/indexing.py", line 560, in __array__
return np.asarray(array[self.key], dtype=None)
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/numpy/core/_asarray.py", line 83, in asarray
return array(a, dtype, copy=False, order=order)
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/xarray/coding/variables.py", line 70, in __array__
return self.func(self.array)
File "/data/gholl/miniconda3/envs/py38b/lib/python3.8/site-packages/xarray/coding/variables.py", line 220, in _scale_offset_decoding
data *= scale_factor
ValueError: non-broadcastable output operand with shape () doesn't match the broadcast shape (1,)

# Fixed code
def decode(self, variable, name=None):
    dims, data, attrs, encoding = unpack_for_decoding(variable)

    if "scale_factor" in attrs or "add_offset" in attrs:
        scale_factor = pop_to(attrs, encoding, "scale_factor", name=name)
        add_offset = pop_to(attrs, encoding, "add_offset", name=name)
        dtype = _choose_float_dtype(data.dtype, "add_offset" in attrs)
        if np.ndim(scale_factor) > 0:
            scale_factor = scale_factor.item()
        if np.ndim(add_offset) > 0:
            add_offset = add_offset.item()
        transform = partial(
            _scale_offset_decoding,
            scale_factor=scale_factor,
            add_offset=add_offset,
            dtype=dtype,
        )
        data = lazy_elemwise_func(data, transform, dtype)

    return Variable(dims, data, attrs, encoding)