From 01fb73b1e81c5f8994125e808ffeea786da5ecc2 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sat, 20 Mar 2021 12:20:21 -0400 Subject: [PATCH] make typing DatetimeLikeScalar a Union instead of TypeVar --- pandas/_typing.py | 2 +- pandas/core/arrays/datetimelike.py | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index e95dff2e69ff0..f90ef33434773 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -80,7 +80,7 @@ # scalars PythonScalar = Union[str, int, float, bool] -DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta") +DatetimeLikeScalar = Union["Period", "Timestamp", "Timedelta"] PandasScalar = Union["Period", "Timestamp", "Timedelta", "Interval"] Scalar = Union[PythonScalar, PandasScalar] diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 0900688e04374..67241a866ef35 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -563,8 +563,7 @@ def _validate_comparison_value(self, other): raise InvalidComparison(other) if isinstance(other, self._recognized_scalars) or other is NaT: - # error: Too many arguments for "object" - other = self._scalar_type(other) # type: ignore[call-arg] + other = self._scalar_type(other) try: self._check_compatible_with(other) except (TypeError, IncompatibleFrequency) as err: @@ -614,16 +613,14 @@ def _validate_shift_value(self, fill_value): if is_valid_na_for_dtype(fill_value, self.dtype): fill_value = NaT elif isinstance(fill_value, self._recognized_scalars): - # error: Too many arguments for "object" - fill_value = self._scalar_type(fill_value) # type: ignore[call-arg] + fill_value = self._scalar_type(fill_value) else: # only warn if we're not going to raise if self._scalar_type is Period and lib.is_integer(fill_value): # kludge for #31971 since Period(integer) tries to cast to str new_fill = Period._from_ordinal(fill_value, freq=self.freq) else: - # error: Too many arguments for "object" - new_fill = self._scalar_type(fill_value) # type: ignore[call-arg] + new_fill = self._scalar_type(fill_value) # stacklevel here is chosen to be correct when called from # DataFrame.shift or Series.shift @@ -684,8 +681,7 @@ def _validate_scalar( raise TypeError(msg) elif isinstance(value, self._recognized_scalars): - # error: Too many arguments for "object" - value = self._scalar_type(value) # type: ignore[call-arg] + value = self._scalar_type(value) else: msg = self._validation_error_message(value, allow_listlike)