Skip to content

Commit cdcb176

Browse files
committed
use pd.array directly
1 parent 309fdf4 commit cdcb176

File tree

3 files changed

+49
-32
lines changed

3 files changed

+49
-32
lines changed

pandas-stubs/core/construction.pyi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
from collections.abc import Sequence
2+
from typing import overload
23

34
import numpy as np
45
from pandas.core.arrays.base import ExtensionArray
6+
from pandas.core.arrays.integer import IntegerArray
7+
8+
from pandas._libs.missing import NAType
59

610
from pandas.core.dtypes.dtypes import ExtensionDtype
711

12+
@overload
13+
def array(
14+
data: Sequence[int] | Sequence[int | NAType],
15+
dtype: str | np.dtype | ExtensionDtype | None = None,
16+
copy: bool = True,
17+
) -> IntegerArray: ...
18+
@overload
819
def array(
920
data: Sequence[object],
1021
dtype: str | np.dtype | ExtensionDtype | None = None,

tests/arrays/test_arrays.py

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,12 @@
1-
from typing import cast
2-
3-
from pandas.core.arrays.integer import (
4-
Int64Dtype,
5-
IntegerArray,
6-
)
7-
from pandas.core.series import Series
1+
from pandas.core.arrays.integer import IntegerArray
2+
from pandas.core.construction import array
83
from typing_extensions import assert_type
94

105
from pandas._libs.missing import NA
116

127
from tests import check
138

149

15-
def test_cumul_int64dtype():
16-
# cast will be removed if pandas-dev/pandas-stubs#1395 is resolved
17-
arr = cast("Series[Int64Dtype]", Series([1, NA, 2], dtype="Int64")).array
18-
19-
check(assert_type(arr._accumulate("cummin"), IntegerArray), IntegerArray)
20-
check(assert_type(arr._accumulate("cummax"), IntegerArray), IntegerArray)
21-
check(assert_type(arr._accumulate("cumsum"), IntegerArray), IntegerArray)
22-
check(assert_type(arr._accumulate("cumprod"), IntegerArray), IntegerArray)
23-
24-
check(
25-
assert_type(arr._accumulate("cummin", skipna=False), IntegerArray),
26-
IntegerArray,
27-
)
28-
check(
29-
assert_type(arr._accumulate("cummax", skipna=False), IntegerArray),
30-
IntegerArray,
31-
)
32-
check(
33-
assert_type(arr._accumulate("cumsum", skipna=False), IntegerArray),
34-
IntegerArray,
35-
)
36-
check(
37-
assert_type(arr._accumulate("cumprod", skipna=False), IntegerArray),
38-
IntegerArray,
39-
)
10+
def test_construction() -> None:
11+
check(assert_type(array([1]), IntegerArray), IntegerArray)
12+
check(assert_type(array([1, NA]), IntegerArray), IntegerArray)

tests/arrays/test_cumul.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from pandas.core.arrays.integer import IntegerArray
2+
from pandas.core.construction import array
3+
from typing_extensions import assert_type
4+
5+
from pandas._libs.missing import NA
6+
7+
from tests import check
8+
9+
10+
def test_cumul_int64dtype() -> None:
11+
arr = array([1, NA, 2])
12+
13+
check(assert_type(arr._accumulate("cummin"), IntegerArray), IntegerArray)
14+
check(assert_type(arr._accumulate("cummax"), IntegerArray), IntegerArray)
15+
check(assert_type(arr._accumulate("cumsum"), IntegerArray), IntegerArray)
16+
check(assert_type(arr._accumulate("cumprod"), IntegerArray), IntegerArray)
17+
18+
check(
19+
assert_type(arr._accumulate("cummin", skipna=False), IntegerArray),
20+
IntegerArray,
21+
)
22+
check(
23+
assert_type(arr._accumulate("cummax", skipna=False), IntegerArray),
24+
IntegerArray,
25+
)
26+
check(
27+
assert_type(arr._accumulate("cumsum", skipna=False), IntegerArray),
28+
IntegerArray,
29+
)
30+
check(
31+
assert_type(arr._accumulate("cumprod", skipna=False), IntegerArray),
32+
IntegerArray,
33+
)

0 commit comments

Comments
 (0)