code: def _astype_float_to_int_nansafe(
      values: np.ndarray, dtype: np.dtype, copy: bool
  ) -> np.ndarray:
      """
      astype with a check preventing converting NaN to an meaningless integer value.
      """
      if not np.isfinite(values).all():
          raise IntCastingNaNError(
              "Cannot convert non-finite values (NA or inf) to integer"
          )
      if dtype.kind == "u":
          # GH#45151
          if not (values >= 0).all():
              raise ValueError(
                  f"Cannot losslessly cast from {values.dtype} to {dtype}"
              )
      with warnings.catch_warnings():
          warnings.filterwarnings("ignore", category=RuntimeWarning)
          return values.astype(dtype, copy=copy)
  
file_path: catboost/contrib/python/pandas/py3/pandas/core/dtypes/astype.py
imports: from __future__ import annotations
  import inspect
  from typing import TYPE_CHECKING, overload
  import warnings
  import numpy
  from pandas._libs import lib
  from pandas._libs.tslibs.timedeltas import array_to_timedelta64
  from pandas._typing import ArrayLike, DtypeObj, IgnoreRaise
  from pandas.errors import IntCastingNaNError
  from pandas.core.dtypes.common import is_datetime64_dtype, is_dtype_equal, is_integer_dtype, is_object_dtype, is_string_dtype, is_timedelta64_dtype, pandas_dtype
  from pandas.core.dtypes.dtypes import ExtensionDtype, PandasDtype
label_desc: Use image node_id 4 for calling a global function with example usage: _astype_float_to_int_nansafe(values, dtype, copy) and returns: values