diff --git a/pandas/core/arrays/__init__.py b/pandas/core/arrays/__init__.py index e5258a6aecd30..93f679d13b33c 100644 --- a/pandas/core/arrays/__init__.py +++ b/pandas/core/arrays/__init__.py @@ -7,7 +7,7 @@ from pandas.core.arrays.categorical import Categorical from pandas.core.arrays.datetimes import DatetimeArray from pandas.core.arrays.floating import FloatingArray -from pandas.core.arrays.integer import IntegerArray, integer_array +from pandas.core.arrays.integer import IntegerArray from pandas.core.arrays.interval import IntervalArray from pandas.core.arrays.masked import BaseMaskedArray from pandas.core.arrays.numpy_ import PandasArray, PandasDtype @@ -26,7 +26,6 @@ "DatetimeArray", "FloatingArray", "IntegerArray", - "integer_array", "IntervalArray", "PandasArray", "PandasDtype", diff --git a/pandas/core/arrays/integer.py b/pandas/core/arrays/integer.py index fa427e94fe08f..6a19a3aea3eee 100644 --- a/pandas/core/arrays/integer.py +++ b/pandas/core/arrays/integer.py @@ -121,29 +121,6 @@ def __from_arrow__( return IntegerArray._concat_same_type(results) -def integer_array(values, dtype=None, copy: bool = False) -> "IntegerArray": - """ - Infer and return an integer array of the values. - - Parameters - ---------- - values : 1D list-like - dtype : dtype, optional - dtype to coerce - copy : bool, default False - - Returns - ------- - IntegerArray - - Raises - ------ - TypeError if incompatible types - """ - values, mask = coerce_to_array(values, dtype=dtype, copy=copy) - return IntegerArray(values, mask) - - def safe_cast(values, dtype, copy: bool): """ Safely cast the values to the dtype if they @@ -360,7 +337,8 @@ def __abs__(self): def _from_sequence( cls, scalars, *, dtype=None, copy: bool = False ) -> "IntegerArray": - return integer_array(scalars, dtype=dtype, copy=copy) + values, mask = coerce_to_array(scalars, dtype=dtype, copy=copy) + return IntegerArray(values, mask) @classmethod def _from_sequence_of_strings( diff --git a/pandas/tests/arrays/integer/conftest.py b/pandas/tests/arrays/integer/conftest.py index 994fccf837f08..080ca180337f0 100644 --- a/pandas/tests/arrays/integer/conftest.py +++ b/pandas/tests/arrays/integer/conftest.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from pandas.core.arrays import integer_array +import pandas as pd from pandas.core.arrays.integer import ( Int8Dtype, Int16Dtype, @@ -32,7 +32,7 @@ def dtype(request): @pytest.fixture def data(dtype): - return integer_array( + return pd.array( list(range(8)) + [np.nan] + list(range(10, 98)) + [np.nan] + [99, 100], dtype=dtype, ) @@ -40,7 +40,7 @@ def data(dtype): @pytest.fixture def data_missing(dtype): - return integer_array([np.nan, 1], dtype=dtype) + return pd.array([np.nan, 1], dtype=dtype) @pytest.fixture(params=["data", "data_missing"]) diff --git a/pandas/tests/arrays/integer/test_arithmetic.py b/pandas/tests/arrays/integer/test_arithmetic.py index 617cb6407d857..8ba984e649e35 100644 --- a/pandas/tests/arrays/integer/test_arithmetic.py +++ b/pandas/tests/arrays/integer/test_arithmetic.py @@ -7,7 +7,7 @@ import pandas as pd import pandas._testing as tm -from pandas.core.arrays import FloatingArray, integer_array +from pandas.core.arrays import FloatingArray import pandas.core.ops as ops # Basic test for the arithmetic array ops @@ -131,10 +131,10 @@ def test_pow_scalar(): def test_pow_array(): - a = integer_array([0, 0, 0, 1, 1, 1, None, None, None]) - b = integer_array([0, 1, None, 0, 1, None, 0, 1, None]) + a = pd.array([0, 0, 0, 1, 1, 1, None, None, None]) + b = pd.array([0, 1, None, 0, 1, None, 0, 1, None]) result = a ** b - expected = integer_array([1, 0, None, 1, 1, 1, 1, None, None]) + expected = pd.array([1, 0, None, 1, 1, 1, 1, None, None]) tm.assert_extension_array_equal(result, expected) @@ -149,7 +149,7 @@ def test_rpow_one_to_na(): @pytest.mark.parametrize("other", [0, 0.5]) def test_numpy_zero_dim_ndarray(other): - arr = integer_array([1, None, 2]) + arr = pd.array([1, None, 2]) result = arr + np.array(other) expected = arr + other tm.assert_equal(result, expected) @@ -265,7 +265,7 @@ def test_reduce_to_float(op): { "A": ["a", "b", "b"], "B": [1, None, 3], - "C": integer_array([1, None, 3], dtype="Int64"), + "C": pd.array([1, None, 3], dtype="Int64"), } ) @@ -277,10 +277,7 @@ def test_reduce_to_float(op): result = getattr(df.groupby("A"), op)() expected = pd.DataFrame( - { - "B": np.array([1.0, 3.0]), - "C": pd.array([1, 3], dtype="Float64"), - }, + {"B": np.array([1.0, 3.0]), "C": pd.array([1, 3], dtype="Float64")}, index=pd.Index(["a", "b"], name="A"), ) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/arrays/integer/test_construction.py b/pandas/tests/arrays/integer/test_construction.py index 15307b6f2190e..a7e31ede8e384 100644 --- a/pandas/tests/arrays/integer/test_construction.py +++ b/pandas/tests/arrays/integer/test_construction.py @@ -4,10 +4,15 @@ import pandas as pd import pandas._testing as tm from pandas.api.types import is_integer -from pandas.core.arrays import IntegerArray, integer_array +from pandas.core.arrays import IntegerArray from pandas.core.arrays.integer import Int8Dtype, Int32Dtype, Int64Dtype +@pytest.fixture(params=[pd.array, IntegerArray._from_sequence]) +def constructor(request): + return request.param + + def test_uses_pandas_na(): a = pd.array([1, None], dtype=Int64Dtype()) assert a[1] is pd.NA @@ -65,7 +70,7 @@ def test_integer_array_constructor(): mask = np.array([False, False, False, True], dtype="bool") result = IntegerArray(values, mask) - expected = integer_array([1, 2, 3, np.nan], dtype="int64") + expected = pd.array([1, 2, 3, np.nan], dtype="Int64") tm.assert_extension_array_equal(result, expected) msg = r".* should be .* numpy array. Use the 'pd.array' function instead" @@ -82,21 +87,6 @@ def test_integer_array_constructor(): IntegerArray(values) -@pytest.mark.parametrize( - "a, b", - [ - ([1, None], [1, np.nan]), - ([None], [np.nan]), - ([None, np.nan], [np.nan, np.nan]), - ([np.nan, np.nan], [np.nan, np.nan]), - ], -) -def test_integer_array_constructor_none_is_nan(a, b): - result = integer_array(a) - expected = integer_array(b) - tm.assert_extension_array_equal(result, expected) - - def test_integer_array_constructor_copy(): values = np.array([1, 2, 3, 4], dtype="int64") mask = np.array([False, False, False, True], dtype="bool") @@ -110,6 +100,21 @@ def test_integer_array_constructor_copy(): assert result._mask is not mask +@pytest.mark.parametrize( + "a, b", + [ + ([1, None], [1, np.nan]), + ([None], [np.nan]), + ([None, np.nan], [np.nan, np.nan]), + ([np.nan, np.nan], [np.nan, np.nan]), + ], +) +def test_to_integer_array_none_is_nan(a, b): + result = pd.array(a, dtype="Int64") + expected = pd.array(b, dtype="Int64") + tm.assert_extension_array_equal(result, expected) + + @pytest.mark.parametrize( "values", [ @@ -129,42 +134,46 @@ def test_to_integer_array_error(values): msg = ( r"(:?.* cannot be converted to an IntegerDtype)" r"|(:?values must be a 1D list-like)" + r"|(Cannot pass scalar)" ) + with pytest.raises((ValueError, TypeError), match=msg): + pd.array(values, dtype="Int64") + with pytest.raises(TypeError, match=msg): - integer_array(values) + IntegerArray._from_sequence(values) -def test_to_integer_array_inferred_dtype(): +def test_to_integer_array_inferred_dtype(constructor): # if values has dtype -> respect it - result = integer_array(np.array([1, 2], dtype="int8")) + result = constructor(np.array([1, 2], dtype="int8")) assert result.dtype == Int8Dtype() - result = integer_array(np.array([1, 2], dtype="int32")) + result = constructor(np.array([1, 2], dtype="int32")) assert result.dtype == Int32Dtype() # if values have no dtype -> always int64 - result = integer_array([1, 2]) + result = constructor([1, 2]) assert result.dtype == Int64Dtype() -def test_to_integer_array_dtype_keyword(): - result = integer_array([1, 2], dtype="int8") +def test_to_integer_array_dtype_keyword(constructor): + result = constructor([1, 2], dtype="Int8") assert result.dtype == Int8Dtype() # if values has dtype -> override it - result = integer_array(np.array([1, 2], dtype="int8"), dtype="int32") + result = constructor(np.array([1, 2], dtype="int8"), dtype="Int32") assert result.dtype == Int32Dtype() def test_to_integer_array_float(): - result = integer_array([1.0, 2.0]) - expected = integer_array([1, 2]) + result = IntegerArray._from_sequence([1.0, 2.0]) + expected = pd.array([1, 2], dtype="Int64") tm.assert_extension_array_equal(result, expected) with pytest.raises(TypeError, match="cannot safely cast non-equivalent"): - integer_array([1.5, 2.0]) + IntegerArray._from_sequence([1.5, 2.0]) # for float dtypes, the itemsize is not preserved - result = integer_array(np.array([1.0, 2.0], dtype="float32")) + result = IntegerArray._from_sequence(np.array([1.0, 2.0], dtype="float32")) assert result.dtype == Int64Dtype() @@ -176,10 +185,12 @@ def test_to_integer_array_float(): ([False, True, np.nan], [0, 1, np.nan], Int64Dtype(), Int64Dtype()), ], ) -def test_to_integer_array_bool(bool_values, int_values, target_dtype, expected_dtype): - result = integer_array(bool_values, dtype=target_dtype) +def test_to_integer_array_bool( + constructor, bool_values, int_values, target_dtype, expected_dtype +): + result = constructor(bool_values, dtype=target_dtype) assert result.dtype == expected_dtype - expected = integer_array(int_values, dtype=target_dtype) + expected = pd.array(int_values, dtype=target_dtype) tm.assert_extension_array_equal(result, expected) @@ -193,7 +204,7 @@ def test_to_integer_array_bool(bool_values, int_values, target_dtype, expected_d ) def test_to_integer_array(values, to_dtype, result_dtype): # convert existing arrays to IntegerArrays - result = integer_array(values, dtype=to_dtype) + result = IntegerArray._from_sequence(values, dtype=to_dtype) assert result.dtype == result_dtype() - expected = integer_array(values, dtype=result_dtype()) + expected = pd.array(values, dtype=result_dtype()) tm.assert_extension_array_equal(result, expected) diff --git a/pandas/tests/arrays/integer/test_dtypes.py b/pandas/tests/arrays/integer/test_dtypes.py index d71037f9151e0..4d00a22e13c3a 100644 --- a/pandas/tests/arrays/integer/test_dtypes.py +++ b/pandas/tests/arrays/integer/test_dtypes.py @@ -5,7 +5,6 @@ import pandas as pd import pandas._testing as tm -from pandas.core.arrays import integer_array from pandas.core.arrays.integer import Int8Dtype, UInt32Dtype @@ -28,7 +27,7 @@ def test_preserve_dtypes(op): { "A": ["a", "b", "b"], "B": [1, None, 3], - "C": integer_array([1, None, 3], dtype="Int64"), + "C": pd.array([1, None, 3], dtype="Int64"), } ) @@ -43,7 +42,7 @@ def test_preserve_dtypes(op): result = getattr(df.groupby("A"), op)() expected = pd.DataFrame( - {"B": np.array([1.0, 3.0]), "C": integer_array([1, 3], dtype="Int64")}, + {"B": np.array([1.0, 3.0]), "C": pd.array([1, 3], dtype="Int64")}, index=pd.Index(["a", "b"], name="A"), ) tm.assert_frame_equal(result, expected) @@ -51,7 +50,7 @@ def test_preserve_dtypes(op): def test_astype_nansafe(): # see gh-22343 - arr = integer_array([np.nan, 1, 2], dtype="Int8") + arr = pd.array([np.nan, 1, 2], dtype="Int8") msg = "cannot convert to 'uint32'-dtype NumPy array with missing values." with pytest.raises(ValueError, match=msg): @@ -69,7 +68,7 @@ def test_construct_index(all_data, dropna): else: other = all_data - result = pd.Index(integer_array(other, dtype=all_data.dtype)) + result = pd.Index(pd.array(other, dtype=all_data.dtype)) expected = pd.Index(other, dtype=object) tm.assert_index_equal(result, expected) @@ -229,14 +228,14 @@ def test_construct_cast_invalid(dtype): msg = "cannot safely" arr = [1.2, 2.3, 3.7] with pytest.raises(TypeError, match=msg): - integer_array(arr, dtype=dtype) + pd.array(arr, dtype=dtype) with pytest.raises(TypeError, match=msg): pd.Series(arr).astype(dtype) arr = [1.2, 2.3, 3.7, np.nan] with pytest.raises(TypeError, match=msg): - integer_array(arr, dtype=dtype) + pd.array(arr, dtype=dtype) with pytest.raises(TypeError, match=msg): pd.Series(arr).astype(dtype) diff --git a/pandas/tests/arrays/integer/test_function.py b/pandas/tests/arrays/integer/test_function.py index 521547cc7357d..3a0ecee960e88 100644 --- a/pandas/tests/arrays/integer/test_function.py +++ b/pandas/tests/arrays/integer/test_function.py @@ -3,27 +3,26 @@ import pandas as pd import pandas._testing as tm -from pandas.core.arrays import integer_array @pytest.mark.parametrize("ufunc", [np.abs, np.sign]) # np.sign emits a warning with nans, @pytest.mark.filterwarnings("ignore:invalid value encountered in sign") def test_ufuncs_single_int(ufunc): - a = integer_array([1, 2, -3, np.nan]) + a = pd.array([1, 2, -3, np.nan]) result = ufunc(a) - expected = integer_array(ufunc(a.astype(float))) + expected = pd.array(ufunc(a.astype(float)), dtype="Int64") tm.assert_extension_array_equal(result, expected) s = pd.Series(a) result = ufunc(s) - expected = pd.Series(integer_array(ufunc(a.astype(float)))) + expected = pd.Series(pd.array(ufunc(a.astype(float)), dtype="Int64")) tm.assert_series_equal(result, expected) @pytest.mark.parametrize("ufunc", [np.log, np.exp, np.sin, np.cos, np.sqrt]) def test_ufuncs_single_float(ufunc): - a = integer_array([1, 2, -3, np.nan]) + a = pd.array([1, 2, -3, np.nan]) with np.errstate(invalid="ignore"): result = ufunc(a) expected = ufunc(a.astype(float)) @@ -39,33 +38,33 @@ def test_ufuncs_single_float(ufunc): @pytest.mark.parametrize("ufunc", [np.add, np.subtract]) def test_ufuncs_binary_int(ufunc): # two IntegerArrays - a = integer_array([1, 2, -3, np.nan]) + a = pd.array([1, 2, -3, np.nan]) result = ufunc(a, a) - expected = integer_array(ufunc(a.astype(float), a.astype(float))) + expected = pd.array(ufunc(a.astype(float), a.astype(float)), dtype="Int64") tm.assert_extension_array_equal(result, expected) # IntegerArray with numpy array arr = np.array([1, 2, 3, 4]) result = ufunc(a, arr) - expected = integer_array(ufunc(a.astype(float), arr)) + expected = pd.array(ufunc(a.astype(float), arr), dtype="Int64") tm.assert_extension_array_equal(result, expected) result = ufunc(arr, a) - expected = integer_array(ufunc(arr, a.astype(float))) + expected = pd.array(ufunc(arr, a.astype(float)), dtype="Int64") tm.assert_extension_array_equal(result, expected) # IntegerArray with scalar result = ufunc(a, 1) - expected = integer_array(ufunc(a.astype(float), 1)) + expected = pd.array(ufunc(a.astype(float), 1), dtype="Int64") tm.assert_extension_array_equal(result, expected) result = ufunc(1, a) - expected = integer_array(ufunc(1, a.astype(float))) + expected = pd.array(ufunc(1, a.astype(float)), dtype="Int64") tm.assert_extension_array_equal(result, expected) def test_ufunc_binary_output(): - a = integer_array([1, 2, np.nan]) + a = pd.array([1, 2, np.nan]) result = np.modf(a) expected = np.modf(a.to_numpy(na_value=np.nan, dtype="float")) @@ -74,13 +73,13 @@ def test_ufunc_binary_output(): for x, y in zip(result, expected): # TODO(FloatArray): This will return an extension array. - # y = integer_array(y) + # y = pd.array(y) tm.assert_numpy_array_equal(x, y) @pytest.mark.parametrize("values", [[0, 1], [0, None]]) def test_ufunc_reduce_raises(values): - a = integer_array(values) + a = pd.array(values) msg = r"The 'reduce' method is not supported." with pytest.raises(NotImplementedError, match=msg): np.add.reduce(a) diff --git a/pandas/tests/arrays/integer/test_repr.py b/pandas/tests/arrays/integer/test_repr.py index bdc5724e85e0d..35d07bda9a333 100644 --- a/pandas/tests/arrays/integer/test_repr.py +++ b/pandas/tests/arrays/integer/test_repr.py @@ -2,7 +2,6 @@ import pytest import pandas as pd -from pandas.core.arrays import integer_array from pandas.core.arrays.integer import ( Int8Dtype, Int16Dtype, @@ -43,13 +42,13 @@ def test_repr_dtype(dtype, expected): def test_repr_array(): - result = repr(integer_array([1, None, 3])) + result = repr(pd.array([1, None, 3])) expected = "\n[1, , 3]\nLength: 3, dtype: Int64" assert result == expected def test_repr_array_long(): - data = integer_array([1, 2, None] * 1000) + data = pd.array([1, 2, None] * 1000) expected = ( "\n" "[ 1, 2, , 1, 2, , 1, 2, , 1,\n" diff --git a/pandas/tests/arrays/test_array.py b/pandas/tests/arrays/test_array.py index 72deada4eaf43..779cb7a2350ee 100644 --- a/pandas/tests/arrays/test_array.py +++ b/pandas/tests/arrays/test_array.py @@ -21,7 +21,7 @@ StringArray, TimedeltaArray, ) -from pandas.core.arrays import PandasArray, integer_array, period_array +from pandas.core.arrays import PandasArray, period_array from pandas.tests.extension.decimal import DecimalArray, DecimalDtype, to_decimal @@ -122,7 +122,7 @@ # Sparse ([0, 1], "Sparse[int64]", SparseArray([0, 1], dtype="int64")), # IntegerNA - ([1, None], "Int16", integer_array([1, None], dtype="Int16")), + ([1, None], "Int16", pd.array([1, None], dtype="Int16")), (pd.Series([1, 2]), None, PandasArray(np.array([1, 2], dtype=np.int64))), # String (["a", None], "string", StringArray._from_sequence(["a", None])), diff --git a/pandas/tests/base/test_conversion.py b/pandas/tests/base/test_conversion.py index cc4aed5e4413d..94330f861eacd 100644 --- a/pandas/tests/base/test_conversion.py +++ b/pandas/tests/base/test_conversion.py @@ -240,7 +240,7 @@ def test_numpy_array_all_dtypes(any_numpy_dtype): [ (pd.Categorical(["a", "b"]), "_codes"), (pd.core.arrays.period_array(["2000", "2001"], freq="D"), "_data"), - (pd.core.arrays.integer_array([0, np.nan]), "_data"), + (pd.array([0, np.nan], dtype="Int64"), "_data"), (IntervalArray.from_breaks([0, 1]), "_left"), (SparseArray([0, 1]), "_sparse_values"), (DatetimeArray(np.array([1, 2], dtype="datetime64[ns]")), "_data"), @@ -285,7 +285,7 @@ def test_array_multiindex_raises(): pd.core.arrays.period_array(["2000", "2001"], freq="D"), np.array([pd.Period("2000", freq="D"), pd.Period("2001", freq="D")]), ), - (pd.core.arrays.integer_array([0, np.nan]), np.array([0, pd.NA], dtype=object)), + (pd.array([0, np.nan], dtype="Int64"), np.array([0, pd.NA], dtype=object)), ( IntervalArray.from_breaks([0, 1, 2]), np.array([pd.Interval(0, 1), pd.Interval(1, 2)], dtype=object), diff --git a/pandas/tests/extension/test_integer.py b/pandas/tests/extension/test_integer.py index b1461dcbd9e53..99a32203053c6 100644 --- a/pandas/tests/extension/test_integer.py +++ b/pandas/tests/extension/test_integer.py @@ -20,7 +20,6 @@ import pandas as pd import pandas._testing as tm -from pandas.core.arrays import integer_array from pandas.core.arrays.integer import ( Int8Dtype, Int16Dtype, @@ -56,27 +55,27 @@ def dtype(request): @pytest.fixture def data(dtype): - return integer_array(make_data(), dtype=dtype) + return pd.array(make_data(), dtype=dtype) @pytest.fixture def data_for_twos(dtype): - return integer_array(np.ones(100) * 2, dtype=dtype) + return pd.array(np.ones(100) * 2, dtype=dtype) @pytest.fixture def data_missing(dtype): - return integer_array([pd.NA, 1], dtype=dtype) + return pd.array([pd.NA, 1], dtype=dtype) @pytest.fixture def data_for_sorting(dtype): - return integer_array([1, 2, 0], dtype=dtype) + return pd.array([1, 2, 0], dtype=dtype) @pytest.fixture def data_missing_for_sorting(dtype): - return integer_array([1, pd.NA, 0], dtype=dtype) + return pd.array([1, pd.NA, 0], dtype=dtype) @pytest.fixture @@ -96,7 +95,7 @@ def data_for_grouping(dtype): a = 0 c = 2 na = pd.NA - return integer_array([b, b, na, na, a, a, b, c], dtype=dtype) + return pd.array([b, b, na, na, a, a, b, c], dtype=dtype) class TestDtype(base.BaseDtypeTests): diff --git a/pandas/tests/frame/methods/test_astype.py b/pandas/tests/frame/methods/test_astype.py index d79969eac0323..54559400e3510 100644 --- a/pandas/tests/frame/methods/test_astype.py +++ b/pandas/tests/frame/methods/test_astype.py @@ -3,6 +3,7 @@ import numpy as np import pytest +import pandas as pd from pandas import ( Categorical, CategoricalDtype, @@ -20,7 +21,6 @@ option_context, ) import pandas._testing as tm -from pandas.core.arrays import integer_array def _check_cast(df, v): @@ -296,8 +296,8 @@ def test_astype_extension_dtypes(self, dtype): expected1 = DataFrame( { - "a": integer_array([1, 3, 5], dtype=dtype), - "b": integer_array([2, 4, 6], dtype=dtype), + "a": pd.array([1, 3, 5], dtype=dtype), + "b": pd.array([2, 4, 6], dtype=dtype), } ) tm.assert_frame_equal(df.astype(dtype), expected1) @@ -307,7 +307,7 @@ def test_astype_extension_dtypes(self, dtype): df = DataFrame([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], columns=["a", "b"]) df["b"] = df["b"].astype(dtype) expected2 = DataFrame( - {"a": [1.0, 3.0, 5.0], "b": integer_array([2, 4, 6], dtype=dtype)} + {"a": [1.0, 3.0, 5.0], "b": pd.array([2, 4, 6], dtype=dtype)} ) tm.assert_frame_equal(df, expected2) @@ -319,13 +319,13 @@ def test_astype_extension_dtypes_1d(self, dtype): # GH#22578 df = DataFrame({"a": [1.0, 2.0, 3.0]}) - expected1 = DataFrame({"a": integer_array([1, 2, 3], dtype=dtype)}) + expected1 = DataFrame({"a": pd.array([1, 2, 3], dtype=dtype)}) tm.assert_frame_equal(df.astype(dtype), expected1) tm.assert_frame_equal(df.astype("int64").astype(dtype), expected1) df = DataFrame({"a": [1.0, 2.0, 3.0]}) df["a"] = df["a"].astype(dtype) - expected2 = DataFrame({"a": integer_array([1, 2, 3], dtype=dtype)}) + expected2 = DataFrame({"a": pd.array([1, 2, 3], dtype=dtype)}) tm.assert_frame_equal(df, expected2) tm.assert_frame_equal(df.astype(dtype), expected1) diff --git a/pandas/tests/frame/methods/test_get_numeric_data.py b/pandas/tests/frame/methods/test_get_numeric_data.py index d73dbdf045be3..25b2a41b4b3a5 100644 --- a/pandas/tests/frame/methods/test_get_numeric_data.py +++ b/pandas/tests/frame/methods/test_get_numeric_data.py @@ -1,8 +1,9 @@ import numpy as np +import pandas as pd from pandas import Categorical, DataFrame, Index, Series, Timestamp import pandas._testing as tm -from pandas.core.arrays import IntervalArray, integer_array +from pandas.core.arrays import IntervalArray class TestGetNumericData: @@ -85,9 +86,9 @@ def test_get_numeric_data_extension_dtype(self): # GH#22290 df = DataFrame( { - "A": integer_array([-10, np.nan, 0, 10, 20, 30], dtype="Int64"), + "A": pd.array([-10, np.nan, 0, 10, 20, 30], dtype="Int64"), "B": Categorical(list("abcabc")), - "C": integer_array([0, 1, 2, 3, np.nan, 5], dtype="UInt8"), + "C": pd.array([0, 1, 2, 3, np.nan, 5], dtype="UInt8"), "D": IntervalArray.from_breaks(range(7)), } ) diff --git a/pandas/tests/frame/test_stack_unstack.py b/pandas/tests/frame/test_stack_unstack.py index 06e5169fc6016..9825bcb0b5d57 100644 --- a/pandas/tests/frame/test_stack_unstack.py +++ b/pandas/tests/frame/test_stack_unstack.py @@ -1081,7 +1081,7 @@ def test_unstack_mixed_extension_types(self, level): index = MultiIndex.from_tuples([("A", 0), ("A", 1), ("B", 1)], names=["a", "b"]) df = DataFrame( { - "A": pd.core.arrays.integer_array([0, 1, None]), + "A": pd.array([0, 1, None], dtype="Int64"), "B": pd.Categorical(["a", "a", "b"]), }, index=index, diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index f750b3667cec2..5dee5c7f7adad 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -963,12 +963,12 @@ def test_extension_array_cross_section(): # A cross-section of a homogeneous EA should be an EA df = DataFrame( { - "A": pd.core.arrays.integer_array([1, 2]), - "B": pd.core.arrays.integer_array([3, 4]), + "A": pd.array([1, 2], dtype="Int64"), + "B": pd.array([3, 4], dtype="Int64"), }, index=["a", "b"], ) - expected = Series(pd.core.arrays.integer_array([1, 3]), index=["A", "B"], name="a") + expected = Series(pd.array([1, 3], dtype="Int64"), index=["A", "B"], name="a") result = df.loc["a"] tm.assert_series_equal(result, expected) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index c66334065ea63..06a4474fcb3a6 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -15,7 +15,6 @@ import pandas as pd from pandas import DataFrame, MultiIndex, PeriodIndex, Series, bdate_range, date_range import pandas._testing as tm -from pandas.core.arrays import integer_array from pandas.tests.plotting.common import TestPlotBase, _check_plot_works from pandas.io.formats.printing import pprint_thing @@ -173,7 +172,7 @@ def test_nullable_int_plot(self): def test_integer_array_plot(self): # GH 25587 - arr = integer_array([1, 2, 3, 4], dtype="UInt32") + arr = pd.array([1, 2, 3, 4], dtype="UInt32") s = Series(arr) _check_plot_works(s.plot.line) diff --git a/pandas/tests/reshape/concat/test_concat.py b/pandas/tests/reshape/concat/test_concat.py index cd58df4fc5da6..16c4e9456aa05 100644 --- a/pandas/tests/reshape/concat/test_concat.py +++ b/pandas/tests/reshape/concat/test_concat.py @@ -429,7 +429,7 @@ def test_concat_order(self): tm.assert_index_equal(result, expected) def test_concat_different_extension_dtypes_upcasts(self): - a = Series(pd.core.arrays.integer_array([1, 2])) + a = Series(pd.array([1, 2], dtype="Int64")) b = Series(to_decimal([1, 2])) result = pd.concat([a, b], ignore_index=True)