code: def test_nan2zero():
      # Test conditions under which nans written to zero, and error conditions
      # nan2zero as argument to `to_fileobj` deprecated, raises error if not the
      # same as input nan2zero - meaning that by default, nan2zero of False will
      # raise an error.
      arr = np.array([np.nan, 99.0], dtype=np.float32)
      for awt, kwargs in (
          (ArrayWriter, dict(check_scaling=False)),
          (SlopeArrayWriter, dict(calc_scale=False)),
          (SlopeInterArrayWriter, dict(calc_scale=False)),
      ):
          # nan2zero default is True
          # nan2zero ignored for floats
          aw = awt(arr, np.float32, **kwargs)
          data_back = round_trip(aw)
          assert_array_equal(np.isnan(data_back), [True, False])
          # set explicitly
          aw = awt(arr, np.float32, nan2zero=True, **kwargs)
          data_back = round_trip(aw)
          assert_array_equal(np.isnan(data_back), [True, False])
          # Integer output with nan2zero gives zero
          aw = awt(arr, np.int32, **kwargs)
          data_back = round_trip(aw)
          assert_array_equal(data_back, [0, 99])
          # Integer output with nan2zero=False gives whatever astype gives
          aw = awt(arr, np.int32, nan2zero=False, **kwargs)
          data_back = round_trip(aw)
          astype_res = np.array(np.nan).astype(np.int32)
          assert_array_equal(data_back, [astype_res, 99])
  
imports: import itertools
  from io import BytesIO
  from platform import machine, python_compiler
  import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from ..arraywriters import ArrayWriter, ScalingError, SlopeArrayWriter, SlopeInterArrayWriter, WriterError, get_slope_inter, make_array_writer
  from ..casting import int_abs, sctypes, shared_range, type_info
  from ..testing import assert_allclose_safely, suppress_warnings
  from ..volumeutils import _dt_min_max, apply_read_scaling, array_from_file
label_desc: Use image node_id 15 for calling a global function with example usage: test_nan2zero() without return types