Skip to content

Commit c2329f3

Browse files
committed
type fixes
1 parent 8c7f344 commit c2329f3

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

pandas/tests/extension/uuid/test_uuid.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
TYPE_CHECKING,
99
ClassVar,
1010
Self,
11+
cast,
1112
get_args,
13+
overload,
1214
)
1315
from uuid import UUID
1416

@@ -28,6 +30,13 @@
2830

2931
from numpy.typing import NDArray
3032

33+
from pandas._typing import (
34+
Dtype,
35+
PositionalIndexer,
36+
ScalarIndexer,
37+
SequenceIndexer,
38+
)
39+
3140
from pandas.core.arrays.boolean import BooleanArray
3241

3342

@@ -89,16 +98,22 @@ def __init__(self, values: Iterable[UuidLike], *, copy: bool = False) -> None:
8998
@classmethod
9099
def _from_sequence(
91100
cls,
92-
data: Iterable[UuidLike],
93-
dtype: UuidDtype | None = None,
101+
scalars: Iterable[UuidLike],
102+
*,
103+
dtype: Dtype | None = None,
94104
copy: bool = False,
95105
) -> Self:
96106
if dtype is None:
97107
dtype = UuidDtype()
98-
return cls(data, copy=copy)
108+
return cls(scalars, copy=copy)
109+
110+
@overload
111+
def __getitem__(self, index: ScalarIndexer) -> UUID: ...
112+
@overload
113+
def __getitem__(self, index: SequenceIndexer) -> Self: ...
99114

100-
def __getitem__(self, index) -> Self | UUID:
101-
if isinstance(index, int):
115+
def __getitem__(self, index: PositionalIndexer) -> Self | UUID:
116+
if isinstance(index, int | np.integer):
102117
return UUID(bytes=self._data[index].tobytes())
103118
index = check_array_indexer(self, index)
104119
return self._simple_new(self._data[index])
@@ -107,17 +122,18 @@ def __len__(self) -> int:
107122
return len(self._data)
108123

109124
@unpack_zerodim_and_defer("__eq__")
110-
def __eq__(self, other: object) -> BooleanArray:
125+
def __eq__(self, other: object) -> BooleanArray: # type: ignore[override]
111126
return self._cmp("eq", other)
112127

128+
@property
113129
def nbytes(self) -> int:
114130
return self._data.nbytes
115131

116132
def isna(self) -> NDArray[np.bool_]:
117133
return pd.isna(self._data)
118134

119135
def take(
120-
self, indexer, *, allow_fill: bool = False, fill_value: UUID | None = None
136+
self, indexer, *, allow_fill: bool = False, fill_value: object = None
121137
) -> Self:
122138
if allow_fill and fill_value is None:
123139
fill_value = self.dtype.na_value
@@ -153,8 +169,7 @@ def _cmp(self, op: str, other) -> BooleanArray:
153169
method = getattr(self._data, f"__{op}__")
154170
result = method(other)
155171

156-
rv: BooleanArray = pd.array(result, dtype="boolean")
157-
return rv
172+
return cast("BooleanArray", pd.array(result, dtype="boolean"))
158173

159174

160175
def test_construct() -> None:

0 commit comments

Comments
 (0)