Inzynierka/Lib/site-packages/pandas/tests/series/methods/test_to_numpy.py

26 lines
623 B
Python
Raw Permalink Normal View History

2023-06-02 12:51:02 +02:00
import numpy as np
import pytest
from pandas import (
NA,
Series,
)
import pandas._testing as tm
@pytest.mark.parametrize("dtype", ["int64", "float64"])
def test_to_numpy_na_value(dtype):
# GH#48951
ser = Series([1, 2, NA, 4])
result = ser.to_numpy(dtype=dtype, na_value=0)
expected = np.array([1, 2, 0, 4], dtype=dtype)
tm.assert_numpy_array_equal(result, expected)
def test_to_numpy_cast_before_setting_na():
# GH#50600
ser = Series([1])
result = ser.to_numpy(dtype=np.float64, na_value=np.nan)
expected = np.array([1.0])
tm.assert_numpy_array_equal(result, expected)