Skip to content

Commit 4478efc

Browse files
Dr-Irvyeshsurya
authored andcommitted
TYP: ExtensionArray unique and repeat (pandas-dev#41260)
1 parent 1aa0b92 commit 4478efc

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

pandas/core/arrays/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ def shift(self, periods: int = 1, fill_value: object = None) -> ExtensionArray:
794794
b = empty
795795
return self._concat_same_type([a, b])
796796

797-
def unique(self):
797+
def unique(self: ExtensionArrayT) -> ExtensionArrayT:
798798
"""
799799
Compute the ExtensionArray of unique values.
800800
@@ -1023,7 +1023,7 @@ def factorize(self, na_sentinel: int = -1) -> tuple[np.ndarray, ExtensionArray]:
10231023

10241024
@Substitution(klass="ExtensionArray")
10251025
@Appender(_extension_array_shared_docs["repeat"])
1026-
def repeat(self, repeats, axis=None):
1026+
def repeat(self, repeats: int | Sequence[int], axis: int | None = None):
10271027
nv.validate_repeat((), {"axis": axis})
10281028
ind = np.arange(len(self)).repeat(repeats)
10291029
return self.take(ind)

pandas/core/arrays/interval.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,11 @@ def delete(self: IntervalArrayT, loc) -> IntervalArrayT:
15181518
return self._shallow_copy(left=new_left, right=new_right)
15191519

15201520
@Appender(_extension_array_shared_docs["repeat"] % _shared_docs_kwargs)
1521-
def repeat(self: IntervalArrayT, repeats: int, axis=None) -> IntervalArrayT:
1521+
def repeat(
1522+
self: IntervalArrayT,
1523+
repeats: int | Sequence[int],
1524+
axis: int | None = None,
1525+
) -> IntervalArrayT:
15221526
nv.validate_repeat((), {"axis": axis})
15231527
left_repeat = self.left.repeat(repeats)
15241528
right_repeat = self.right.repeat(repeats)

pandas/core/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import pandas._libs.lib as lib
1818
from pandas._typing import (
19+
ArrayLike,
1920
Dtype,
2021
DtypeObj,
2122
IndexLabel,
@@ -996,7 +997,7 @@ def unique(self):
996997
values = self._values
997998

998999
if not isinstance(values, np.ndarray):
999-
result = values.unique()
1000+
result: ArrayLike = values.unique()
10001001
if self.dtype.kind in ["m", "M"] and isinstance(self, ABCSeries):
10011002
# GH#31182 Series._values returns EA, unpack for backward-compat
10021003
if getattr(self.dtype, "tz", None) is None:

0 commit comments

Comments
 (0)