code: def test_a2f_nan2zero():
      # Test conditions under which nans written to zero
      arr = np.array([np.nan, 99.0], dtype=np.float32)
      str_io = BytesIO()
      array_to_file(arr, str_io)
      data_back = array_from_file(arr.shape, np.float32, str_io)
      assert_array_equal(np.isnan(data_back), [True, False])
      # nan2zero ignored for floats
      array_to_file(arr, str_io, nan2zero=True)
      data_back = array_from_file(arr.shape, np.float32, str_io)
      assert_array_equal(np.isnan(data_back), [True, False])
      # Integer output with nan2zero gives zero
      with np.errstate(invalid="ignore"):
          array_to_file(arr, str_io, np.int32, nan2zero=True)
      data_back = array_from_file(arr.shape, np.int32, str_io)
      assert_array_equal(data_back, [0, 99])
      # Integer output with nan2zero=False gives whatever astype gives
      with np.errstate(invalid="ignore"):
          array_to_file(arr, str_io, np.int32, nan2zero=False)
      data_back = array_from_file(arr.shape, np.int32, str_io)
      assert_array_equal(
          data_back, [np.array(np.nan).astype(np.int32), 99]
      )
  
file_path: nibabel/nibabel/tests/test_scaling.py
imports: import warnings
  from io import BytesIO
  import numpy
  import pytest
  from numpy.testing import assert_array_equal
  from ..casting import sctypes, type_info
  from ..testing import suppress_warnings
  from ..volumeutils import apply_read_scaling, array_from_file, array_to_file, finite_range
  from .test_volumeutils import _calculate_scale
label_desc: Use image node_id 4 for calling a global function with example usage: test_a2f_nan2zero() without return types