Skip to content

TYP: fix ignores #41702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,8 @@ def sanitize_array(
# TODO: copy?
subarr = maybe_convert_platform(data)
if subarr.dtype == object:
# Argument 1 to "maybe_infer_to_datetimelike" has incompatible
# type "Union[ExtensionArray, ndarray]"; expected "ndarray"
subarr = maybe_infer_to_datetimelike(subarr) # type: ignore[arg-type]
subarr = cast(np.ndarray, subarr)
subarr = maybe_infer_to_datetimelike(subarr)

subarr = _sanitize_ndim(subarr, data, dtype, index, allow_2d=allow_2d)

Expand Down Expand Up @@ -620,9 +619,7 @@ def _sanitize_ndim(
if is_object_dtype(dtype) and isinstance(dtype, ExtensionDtype):
# i.e. PandasDtype("O")

# error: Argument "dtype" to "asarray_tuplesafe" has incompatible type
# "Type[object]"; expected "Union[str, dtype[Any], None]"
result = com.asarray_tuplesafe(data, dtype=object) # type: ignore[arg-type]
result = com.asarray_tuplesafe(data, dtype=np.dtype("object"))
cls = dtype.construct_array_type()
result = cls._from_sequence(result, dtype=dtype)
else:
Expand Down
26 changes: 8 additions & 18 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ def maybe_convert_platform(
arr = values

if arr.dtype == object:
# error: Argument 1 to "maybe_convert_objects" has incompatible type
# "Union[ExtensionArray, ndarray]"; expected "ndarray"
arr = lib.maybe_convert_objects(arr) # type: ignore[arg-type]
arr = cast(np.ndarray, arr)
arr = lib.maybe_convert_objects(arr)

return arr

Expand Down Expand Up @@ -1249,13 +1248,12 @@ def astype_array(values: ArrayLike, dtype: DtypeObj, copy: bool = False) -> Arra
return values.copy()
return values

if isinstance(values, ABCExtensionArray):
if not isinstance(values, np.ndarray):
# i.e. ExtensionArray
values = values.astype(dtype, copy=copy)

else:
# error: Argument 1 to "astype_nansafe" has incompatible type "ExtensionArray";
# expected "ndarray"
values = astype_nansafe(values, dtype, copy=copy) # type: ignore[arg-type]
values = astype_nansafe(values, dtype, copy=copy)

# in pandas we don't store numpy str dtypes, so convert to object
if isinstance(dtype, np.dtype) and issubclass(values.dtype.type, str):
Expand Down Expand Up @@ -1958,7 +1956,7 @@ def construct_1d_object_array_from_listlike(values: Sized) -> np.ndarray:


def construct_1d_ndarray_preserving_na(
values: Sequence, dtype: DtypeObj | None = None, copy: bool = False
values: Sequence, dtype: np.dtype | None = None, copy: bool = False
) -> np.ndarray:
"""
Construct a new ndarray, coercing `values` to `dtype`, preserving NA.
Expand Down Expand Up @@ -2003,17 +2001,9 @@ def construct_1d_ndarray_preserving_na(
and isinstance(values, np.ndarray)
and values.dtype.kind == "f"
):
# Argument 2 to "astype_float_to_int_nansafe" has incompatible
# type "Union[dtype[Any], ExtensionDtype]"; expected "dtype[Any]"
return astype_float_to_int_nansafe(
values, dtype, copy=copy # type: ignore[arg-type]
)
return astype_float_to_int_nansafe(values, dtype, copy=copy)
else:
# error: Argument "dtype" to "array" has incompatible type
# "Union[dtype[Any], ExtensionDtype, None]"; expected "Union[dtype[Any],
# None, type, _SupportsDType, str, Union[Tuple[Any, int], Tuple[Any,
# Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]]"
subarr = np.array(values, dtype=dtype, copy=copy) # type: ignore[arg-type]
subarr = np.array(values, dtype=dtype, copy=copy)

return subarr

Expand Down
14 changes: 4 additions & 10 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,8 @@ def interval_range(
if periods is not None:
periods += 1

breaks: np.ndarray | TimedeltaIndex | DatetimeIndex

if is_number(endpoint):
# force consistency between start/end/freq (lower end if freq skips it)
if com.all_not_none(start, end, freq):
Expand All @@ -1190,16 +1192,8 @@ def interval_range(
else:
# delegate to the appropriate range function
if isinstance(endpoint, Timestamp):
# error: Incompatible types in assignment (expression has type
# "DatetimeIndex", variable has type "ndarray")
breaks = date_range( # type: ignore[assignment]
start=start, end=end, periods=periods, freq=freq
)
breaks = date_range(start=start, end=end, periods=periods, freq=freq)
else:
# error: Incompatible types in assignment (expression has type
# "TimedeltaIndex", variable has type "ndarray")
breaks = timedelta_range( # type: ignore[assignment]
start=start, end=end, periods=periods, freq=freq
)
breaks = timedelta_range(start=start, end=end, periods=periods, freq=freq)

return IntervalIndex.from_breaks(breaks, name=name, closed=closed)