class_docstr: Dtype for data stored in :class:`SparseArray`.
  
  This dtype implements the pandas ExtensionDtype interface.
  
  Parameters
  ----------
  dtype : str, ExtensionDtype, numpy.dtype, type, default numpy.float64
      The dtype of the underlying array storing the non-fill value values.
  fill_value : scalar, optional
      The scalar value not stored in the SparseArray. By default, this
      depends on `dtype`.
  
      =========== ==========
      dtype       na_value
      =========== ==========
      float       ``np.nan``
      int         ``0``
      bool        ``False``
      datetime64  ``pd.NaT``
      timedelta64 ``pd.NaT``
      =========== ==========
  
      The default value may be overridden by specifying a `fill_value`.
  
  Attributes
  ----------
  None
  
  Methods
  -------
  None
class_docstr_tok: ["Dtype","for","data","stored","in",":","class",":","`","SparseArray","`",".","This","dtype","implements","the","pandas","ExtensionDtype","interface",".","Parameters","--","--","--","--","--","dtype",":","str",",","ExtensionDtype",",","numpy.dtype",",","type",",","default","numpy.float64","The","dtype","of","the","underlying","array","storing","the","non-fill","value","values",".","fill_value",":","scalar",",","optional","The","scalar","value","not","stored","in","the","SparseArray",".","By","default",",","this","depends","on","`","dtype","`",".","===========","==========","dtype","na_value","===========","==========","float","``","np.nan","``","int","``","0","``","bool","``","False","``","datetime64","``","pd.NaT","``","timedelta64","``","pd.NaT","``","===========","==========","The","default","value","may","be","overridden","by","specifying","a","`","fill_value","`",".","Attributes","--","--","--","--","--","None","Methods","--","--","--","-","None"]
docstr: 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 correct `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]
docstr_tok: ["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","correct","`","dtype","`","and","fill","value","for","that","`","dtype","`",".","Raises","--","--","--","ValueError","When","the","current","fill","value","can","not","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","]"]
code: def update_dtype(self, dtype) -> SparseDtype:
      """
      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 correct `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]
      """
      cls = type(self)
      dtype = pandas_dtype(dtype)
  
      if not isinstance(dtype, cls):
          if not isinstance(dtype, np.dtype):
              raise TypeError(
                  "sparse arrays of extension dtypes not supported"
              )
  
          fv_asarray = np.atleast_1d(np.array(self.fill_value))
          fvarr = astype_array(fv_asarray, dtype)
          # NB: not fv_0d.item(), as that casts dt64->int
          fill_value = fvarr[0]
          dtype = cls(dtype, fill_value=fill_value)
  
      return dtype
  
imports: from __future__ import annotations
  import re
  from typing import TYPE_CHECKING, Any
  import warnings
  import numpy
  from pandas._typing import Dtype, DtypeObj, type_t
  from pandas.errors import PerformanceWarning
  from pandas.util._exceptions import find_stack_level
  from pandas.core.dtypes.astype import astype_array
  from pandas.core.dtypes.base import ExtensionDtype, register_extension_dtype
  from pandas.core.dtypes.common import is_bool_dtype, is_object_dtype, is_scalar, is_string_dtype, pandas_dtype
  from pandas.core.dtypes.missing import isna, na_value_for_dtype
label_desc: Use image node_id 18 for calling the SparseDtype obj's underlying member method code with example usage: obj.update_dtype(dtype) and returns: dtype