Skip to content

Commit 5bb24d4

Browse files
committed
fixes for merge with master
2 parents c83a628 + 0203f8d commit 5bb24d4

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

pandas/core/algorithms.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
AnyArrayLike,
3333
AnySequenceLike,
3434
ArrayLike,
35-
Dtype,
3635
DtypeObj,
3736
FrameOrSeriesUnion,
3837
)
@@ -218,7 +217,7 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
218217

219218

220219
def _reconstruct_data(
221-
values: ArrayLike, dtype: Dtype, original: AnyArrayLike
220+
values: ArrayLike, dtype: DtypeObj, original: AnyArrayLike
222221
) -> ArrayLike:
223222
"""
224223
reverse of _ensure_data

pandas/core/arrays/datetimelike.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@
124124
from pandas.tseries import frequencies
125125

126126
if TYPE_CHECKING:
127+
from typing import Literal
128+
127129
from pandas.core.arrays import (
128130
DatetimeArray,
129131
TimedeltaArray,
@@ -460,9 +462,15 @@ def view(self: DatetimeLikeArrayT) -> DatetimeLikeArrayT:
460462
...
461463

462464
@overload
463-
def view(
464-
self: DatetimeLikeArrayT, dtype: Optional[Dtype] = ...
465-
) -> DatetimeLikeArrayT:
465+
def view(self, dtype: Literal["M8[ns]"]) -> DatetimeArray:
466+
...
467+
468+
@overload
469+
def view(self, dtype: Literal["m8[ns]"]) -> TimedeltaArray:
470+
...
471+
472+
@overload
473+
def view(self, dtype: Optional[Dtype] = ...) -> ArrayLike:
466474
...
467475

468476
def view(self, dtype: Optional[Dtype] = None) -> ArrayLike:

pandas/core/arrays/sparse/dtype.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from pandas.core.dtypes.cast import astype_nansafe
2828
from pandas.core.dtypes.common import (
2929
is_bool_dtype,
30-
is_extension_array_dtype,
3130
is_object_dtype,
3231
is_scalar,
3332
is_string_dtype,
@@ -339,14 +338,10 @@ def update_dtype(self, dtype):
339338
dtype = pandas_dtype(dtype)
340339

341340
if not isinstance(dtype, cls):
342-
if is_extension_array_dtype(dtype):
341+
if not isinstance(dtype, np.dtype):
343342
raise TypeError("sparse arrays of extension dtypes not supported")
344343

345-
# error: Item "ExtensionArray" of "Union[ExtensionArray, ndarray]" has no
346-
# attribute "item"
347-
fill_value = astype_nansafe( # type: ignore[union-attr]
348-
np.array(self.fill_value), dtype
349-
).item()
344+
fill_value = astype_nansafe(np.array(self.fill_value), dtype).item()
350345
dtype = cls(dtype, fill_value=fill_value)
351346

352347
return dtype

pandas/core/dtypes/cast.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
Type,
2626
Union,
2727
cast,
28+
overload,
2829
)
2930
import warnings
3031

@@ -107,6 +108,8 @@
107108
)
108109

109110
if TYPE_CHECKING:
111+
from typing import Literal
112+
110113
from pandas import Series
111114
from pandas.core.arrays import (
112115
DatetimeArray,
@@ -1164,6 +1167,20 @@ def astype_td64_unit_conversion(
11641167
return result
11651168

11661169

1170+
@overload
1171+
def astype_nansafe(
1172+
arr: np.ndarray, dtype: np.dtype, copy: bool = ..., skipna: bool = ...
1173+
) -> np.ndarray:
1174+
...
1175+
1176+
1177+
@overload
1178+
def astype_nansafe(
1179+
arr: np.ndarray, dtype: ExtensionDtype, copy: bool = ..., skipna: bool = ...
1180+
) -> ExtensionArray:
1181+
...
1182+
1183+
11671184
def astype_nansafe(
11681185
arr: np.ndarray, dtype: DtypeObj, copy: bool = True, skipna: bool = False
11691186
) -> ArrayLike:
@@ -1190,14 +1207,10 @@ def astype_nansafe(
11901207
flags = arr.flags
11911208
flat = arr.ravel("K")
11921209
result = astype_nansafe(flat, dtype, copy=copy, skipna=skipna)
1193-
order = "F" if flags.f_contiguous else "C"
1210+
order: Literal["C", "F"] = "F" if flags.f_contiguous else "C"
11941211
# error: Item "ExtensionArray" of "Union[ExtensionArray, ndarray]" has no
11951212
# attribute "reshape"
1196-
# error: No overload variant of "reshape" of "_ArrayOrScalarCommon" matches
1197-
# argument types "Tuple[int, ...]", "str"
1198-
return result.reshape( # type: ignore[union-attr,call-overload]
1199-
arr.shape, order=order
1200-
)
1213+
return result.reshape(arr.shape, order=order) # type: ignore[union-attr]
12011214

12021215
# We get here with 0-dim from sparse
12031216
arr = np.atleast_1d(arr)

pandas/io/formats/format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ def get_format_timedelta64(
17971797
17981798
If box, then show the return in quotes
17991799
"""
1800-
values_int = values.view(np.int64)
1800+
values_int = cast(np.ndarray, values.view(np.int64))
18011801

18021802
consider_values = values_int != iNaT
18031803

0 commit comments

Comments
 (0)