Skip to content

Commit 77f53d3

Browse files
committed
TYP: overload asarray_tuplesafe signature
1 parent 4d9439e commit 77f53d3

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

pandas/core/arrays/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ def __arrow_array__(self, type=None):
15121512
_interval_shared_docs["to_tuples"] % {"return_type": "ndarray", "examples": ""}
15131513
)
15141514
def to_tuples(self, na_tuple=True) -> np.ndarray:
1515-
tuples = com.asarray_tuplesafe(zip(self._left, self._right))
1515+
tuples = com.asarray_tuplesafe(list(zip(self._left, self._right)))
15161516
if not na_tuple:
15171517
# GH 18756
15181518
tuples = np.where(~self.isna(), tuples, np.nan)

pandas/core/common.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,24 @@ def count_not_none(*args) -> int:
225225
return sum(x is not None for x in args)
226226

227227

228-
def asarray_tuplesafe(values, dtype: NpDtype | None = None) -> np.ndarray:
228+
@overload
229+
def asarray_tuplesafe(
230+
values: ArrayLike | list | tuple, dtype: NpDtype | None = ...
231+
) -> np.ndarray:
232+
...
233+
234+
235+
@overload
236+
def asarray_tuplesafe(values: Iterable, dtype: NpDtype | None = ...) -> ArrayLike:
237+
...
238+
239+
240+
def asarray_tuplesafe(values: Iterable, dtype: NpDtype | None = None) -> ArrayLike:
229241

230242
if not (isinstance(values, (list, tuple)) or hasattr(values, "__array__")):
231243
values = list(values)
232244
elif isinstance(values, ABCIndex):
233-
# error: Incompatible return value type (got "Union[ExtensionArray, ndarray]",
234-
# expected "ndarray")
235-
return values._values # type: ignore[return-value]
245+
return values._values
236246

237247
if isinstance(values, list) and dtype in [np.object_, object]:
238248
return construct_1d_object_array_from_listlike(values)

pandas/core/indexes/base.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,7 @@ def __new__(
555555
subarr = com.asarray_tuplesafe(data, dtype=_dtype_obj)
556556
if dtype is None:
557557
# with e.g. a list [1, 2, 3] casting to numeric is _not_ deprecated
558-
# error: Incompatible types in assignment (expression has type
559-
# "Union[ExtensionArray, ndarray[Any, Any]]", variable has type
560-
# "ndarray[Any, Any]")
561-
subarr = _maybe_cast_data_without_dtype( # type: ignore[assignment]
558+
subarr = _maybe_cast_data_without_dtype(
562559
subarr, cast_numeric_deprecated=False
563560
)
564561
dtype = subarr.dtype

0 commit comments

Comments
 (0)