import numpy as np import pytest import pandas as pd import pandas._testing as tm def test_astype(): # with missing values arr = pd.array([True, False, None], dtype="boolean") with pytest.raises(ValueError, match="cannot convert NA to integer"): arr.astype("int64") with pytest.raises(ValueError, match="cannot convert float NaN to"): arr.astype("bool") result = arr.astype("float64") expected = np.array([1, 0, np.nan], dtype="float64") tm.assert_numpy_array_equal(result, expected) result = arr.astype("str") expected = np.array(["True", "False", ""], dtype="