test_to_numpy.py 623 B

12345678910111213141516171819202122232425
  1. import numpy as np
  2. import pytest
  3. from pandas import (
  4. NA,
  5. Series,
  6. )
  7. import pandas._testing as tm
  8. @pytest.mark.parametrize("dtype", ["int64", "float64"])
  9. def test_to_numpy_na_value(dtype):
  10. # GH#48951
  11. ser = Series([1, 2, NA, 4])
  12. result = ser.to_numpy(dtype=dtype, na_value=0)
  13. expected = np.array([1, 2, 0, 4], dtype=dtype)
  14. tm.assert_numpy_array_equal(result, expected)
  15. def test_to_numpy_cast_before_setting_na():
  16. # GH#50600
  17. ser = Series([1])
  18. result = ser.to_numpy(dtype=np.float64, na_value=np.nan)
  19. expected = np.array([1.0])
  20. tm.assert_numpy_array_equal(result, expected)