# 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)
        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)


# Traceback (AttributeError)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-a0b01d6a314b> in <module>
2                   attrs={'scale_factor': [0.01],
3                          'add_offset': [1.0]}).to_dataset()
----> 4 xr.decode_cf(ds)

~/Code/xarray/xarray/conventions.py in decode_cf(obj, concat_characters, mask_and_scale, decode_times, decode_coords, drop_variables, use_cftime, decode_timedelta)
587         raise TypeError("can only decode Dataset or DataStore objects")
588
--> 589     vars, attrs, coord_names = decode_cf_variables(
590         vars,
591         attrs,

~/Code/xarray/xarray/conventions.py in decode_cf_variables(variables, attributes, concat_characters, mask_and_scale, decode_times, decode_coords, drop_variables, use_cftime, decode_timedelta)
490             and stackable(v.dims[-1])
491         )
--> 492         new_vars[k] = decode_cf_variable(
493             k,
494             v,

~/Code/xarray/xarray/conventions.py in decode_cf_variable(name, var, concat_characters, mask_and_scale, decode_times, decode_endianness, stack_char_dim, use_cftime, decode_timedelta)
333             variables.CFScaleOffsetCoder(),
334         ]:
--> 335             var = coder.decode(var, name=name)
336
337     if decode_timedelta:

~/Code/xarray/xarray/coding/variables.py in decode(self, variable, name)
271             dtype = _choose_float_dtype(data.dtype, "add_offset" in attrs)
272             if np.ndim(scale_factor) > 0:
--> 273                 scale_factor = scale_factor.item()
274             if np.ndim(add_offset) > 0:
275                 add_offset = add_offset.item()

AttributeError: 'list' object has no attribute 'item'

# 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 = np.asarray(scale_factor).item()
        if np.ndim(add_offset) > 0:
            add_offset = np.asarray(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)