Skip to content

Commit ed18983

Browse files
Dr-IrvJulianWgs
authored andcommitted
make typing DatetimeLikeScalar a Union instead of TypeVar (pandas-dev#40540)
1 parent 0ecced6 commit ed18983

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

pandas/_typing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
# scalars
8181

8282
PythonScalar = Union[str, int, float, bool]
83-
DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta")
83+
DatetimeLikeScalar = Union["Period", "Timestamp", "Timedelta"]
8484
PandasScalar = Union["Period", "Timestamp", "Timedelta", "Interval"]
8585
Scalar = Union[PythonScalar, PandasScalar]
8686

pandas/core/arrays/datetimelike.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,7 @@ def _validate_comparison_value(self, other):
563563
raise InvalidComparison(other)
564564

565565
if isinstance(other, self._recognized_scalars) or other is NaT:
566-
# error: Too many arguments for "object"
567-
other = self._scalar_type(other) # type: ignore[call-arg]
566+
other = self._scalar_type(other)
568567
try:
569568
self._check_compatible_with(other)
570569
except (TypeError, IncompatibleFrequency) as err:
@@ -614,16 +613,14 @@ def _validate_shift_value(self, fill_value):
614613
if is_valid_na_for_dtype(fill_value, self.dtype):
615614
fill_value = NaT
616615
elif isinstance(fill_value, self._recognized_scalars):
617-
# error: Too many arguments for "object"
618-
fill_value = self._scalar_type(fill_value) # type: ignore[call-arg]
616+
fill_value = self._scalar_type(fill_value)
619617
else:
620618
# only warn if we're not going to raise
621619
if self._scalar_type is Period and lib.is_integer(fill_value):
622620
# kludge for #31971 since Period(integer) tries to cast to str
623621
new_fill = Period._from_ordinal(fill_value, freq=self.freq)
624622
else:
625-
# error: Too many arguments for "object"
626-
new_fill = self._scalar_type(fill_value) # type: ignore[call-arg]
623+
new_fill = self._scalar_type(fill_value)
627624

628625
# stacklevel here is chosen to be correct when called from
629626
# DataFrame.shift or Series.shift
@@ -684,8 +681,7 @@ def _validate_scalar(
684681
raise TypeError(msg)
685682

686683
elif isinstance(value, self._recognized_scalars):
687-
# error: Too many arguments for "object"
688-
value = self._scalar_type(value) # type: ignore[call-arg]
684+
value = self._scalar_type(value)
689685

690686
else:
691687
msg = self._validation_error_message(value, allow_listlike)

0 commit comments

Comments
 (0)