Skip to content

Commit 72cd77e

Browse files
committed
update Scalar to align with pandas-stubs
1 parent f78828b commit 72cd77e

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

doc/source/reference/aliases.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Alias Meaning
7272
:py:type:`ReadCsvBuffer` Additional argument type corresponding to buffers for :meth:`pandas.read_csv`
7373
:py:type:`ReadPickleBuffer` Additional argument type corresponding to buffers for :meth:`pandas.read_pickle`
7474
:py:type:`ReindexMethod` Argument type for ``reindex`` in :meth:`reindex`
75-
:py:type:`Scalar` Basic type that can be stored in :class:`Series`
75+
:py:type:`Scalar` Regular non-object types that can be stored in :class:`Series`
7676
:py:type:`SequenceNotStr` Used for arguments that require sequences, but not plain strings
7777
:py:type:`SliceType` Argument types for ``start`` and ``end`` in :meth:`Index.slice_locs`
7878
:py:type:`SortKind` Argument type for ``kind`` in :meth:`sort_index` and :meth:`sort_values`

pandas/_typing.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,27 @@ def __reversed__(self) -> Iterator[_T_co]: ...
133133

134134
PythonScalar: TypeAlias = str | float | bool
135135
DatetimeLikeScalar: TypeAlias = Union["Period", "Timestamp", "Timedelta"]
136-
PandasScalar: TypeAlias = Union["Period", "Timestamp", "Timedelta", "Interval"]
137-
Scalar: TypeAlias = PythonScalar | PandasScalar | np.datetime64 | np.timedelta64 | date
136+
137+
# aligned with pandas-stubs - typical scalars found in Series. Explicitly leaves
138+
# out object
139+
_IndexIterScalar: TypeAlias = Union[
140+
str,
141+
bytes,
142+
date,
143+
datetime,
144+
timedelta,
145+
np.datetime64,
146+
np.timedelta64,
147+
bool,
148+
int,
149+
float,
150+
"Timestamp",
151+
"Timedelta",
152+
]
153+
Scalar: TypeAlias = Union[
154+
_IndexIterScalar, "Interval", complex, np.integer, np.floating, np.complexfloating
155+
]
156+
138157
IntStrT = TypeVar("IntStrT", bound=int | str)
139158

140159
# timestamp and timedelta convertible types

pandas/core/dtypes/cast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def _maybe_promote(dtype: np.dtype, fill_value=np.nan):
599599
dtype = np.dtype(np.object_)
600600

601601
elif issubclass(dtype.type, np.integer):
602-
if not np_can_cast_scalar(fill_value, dtype): # type: ignore[arg-type]
602+
if not np_can_cast_scalar(fill_value, dtype):
603603
# upcast to prevent overflow
604604
mst = np.min_scalar_type(fill_value)
605605
dtype = np.promote_types(dtype, mst)

0 commit comments

Comments
 (0)