Description
pyright
and mypy
have issues in dealing with overloads on generics that are ambiguous, as pointed out by numpy
. See the following:
- numpy issue: BUG:
NDArray[Any]
methods ignore overload ambiguity numpy/numpy#20099 - pyright discussion: Pyright does not handle overload ambiguity microsoft/pyright#2521
- mypy issue: Overload ambiguity is ignored in
self
-annotated methods python/mypy#11347
Issue comes in to play with respect to subtraction. For pandas, we'd like an untyped Series
to remain untyped, but subtraction of two Series[Timestamp]
to yield Series[Timedelta]
. This doesn't seem possible. Right now, the current stubs return Series[Timestamp]
when subtracting two untyped series, but do return Series[Timedelta]
when subtracting two Series[Timestamp]
. Discovered this by using the new assert_type()
feature.
In the current stubs from MS copied here, we use Series[bool]
, Series[Timestamp]
, Series[Timedelta]
, Series[float]
and Series[int]
as arguments and/or return types of different methods, which sharpens up some of the type checks.
Possible solutions:
- Give up on using generic Series.
- For typing purposes, create
BoolSeries
,TimestampSeries
,TimedeltaSeries
,FloatSeries
andIntSeries
that are typing subclasses ofSeries
that can help with series that have types and those that don't.
Need to experiment with (2), and if it can't work, just remove all the generic stuff.