def update_dtype(self, dtype):
cls = type(self)<EOL>dtype = pandas_dtype(dtype)<EOL>if not isinstance(dtype, cls):<EOL><INDENT>fill_value = astype_nansafe(np.array(self.fill_value),<EOL>dtype).item()<EOL>dtype = cls(dtype, fill_value=fill_value)<EOL><DEDENT>return dtype<EOL>
Convert the SparseDtype to a new dtype.

This takes care of converting the ``fill_value``.

Parameters
----------
dtype : Union[str, numpy.dtype, SparseDtype]
    The new dtype to use.

    * For a SparseDtype, it is simply returned
    * For a NumPy dtype (or str), the current fill value
      is converted to the new dtype, and a SparseDtype
      with `dtype` and the new fill value is returned.

Returns
-------
SparseDtype
    A new SparseDtype with the corret `dtype` and fill value
    for that `dtype`.

Raises
------
ValueError
    When the current fill value cannot be converted to the
    new `dtype` (e.g. trying to convert ``np.nan`` to an
    integer dtype).


Examples
--------
>>> SparseDtype(int, 0).update_dtype(float)
Sparse[float64, 0.0]

>>> SparseDtype(int, 1).update_dtype(SparseDtype(float, np.nan))
Sparse[float64, nan]