-
-
Notifications
You must be signed in to change notification settings - Fork 141
Support for pyright 1.1.310 #716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ from pandas.core.window.rolling import ( | |
) | ||
from typing_extensions import ( | ||
Never, | ||
Self, | ||
TypeAlias, | ||
) | ||
import xarray as xr | ||
|
@@ -302,16 +303,21 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): | |
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> Series[S1]: ... | ||
) -> Self: ... | ||
@overload | ||
def __new__( | ||
cls, | ||
data: object | ||
| _ListLike | ||
| Series[S1] | ||
| dict[int, S1] | ||
| dict[_str, S1] | ||
| None = ..., | ||
data: Series[S1] | dict[int, S1] | dict[_str, S1] = ..., | ||
index: Axes | None = ..., | ||
dtype=..., | ||
name: Hashable | None = ..., | ||
copy: bool = ..., | ||
fastpath: bool = ..., | ||
) -> Self: ... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This overload was previously connected to the next one in terms of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the two Self overloads be combined? edit: Should we relax edit2: The following replaces the last three overloads and passes all tests with pyright (but not mypy): @overload
def __new__(
cls,
data: Series[S1] | dict[int, S1] | dict[_str, S1] | object= ...,
index: Axes | None = ...,
dtype: type[S1] | type | str | None=...,
name: Hashable = ...,
copy: bool = ...,
fastpath: bool = ...,
) -> Self: ... About mypy errors: since they now have more frequent releases, I wouldn't mind making changes that break mypy-compatibility IF 1) there is a long-standing mypy issue, 2) after informing them that we will break compatibility, and 3) if it helps clean pandas-stubs up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The reason I separated them is that we want to allow people to have an untyped
No. I want to make it that if we know the type and can do something special with it (e.g.,
See above reason why I don't want to combine them. The
I'm more hesitant to do that. Most of our bug reports from the community are things people find by using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I didn't mean to use |
||
@overload | ||
def __new__( | ||
cls, | ||
data: object | _ListLike | None = ..., | ||
index: Axes | None = ..., | ||
dtype=..., | ||
name: Hashable | None = ..., | ||
|
@@ -1923,7 +1929,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]): | |
# ignore needed because of mypy, for using `Never` as type-var. | ||
@overload | ||
def sum( | ||
self: Series[Never], # type: ignore[type-var] | ||
self: Series[Never], | ||
axis: AxisIndex | None = ..., | ||
skipna: _bool | None = ..., | ||
level: None = ..., | ||
|
@@ -2008,16 +2014,16 @@ class TimestampSeries(Series[Timestamp]): | |
# ignore needed because of mypy | ||
@property | ||
def dt(self) -> TimestampProperties: ... # type: ignore[override] | ||
def __add__(self, other: TimedeltaSeries | np.timedelta64) -> TimestampSeries: ... # type: ignore[override] | ||
def __radd__(self, other: TimedeltaSeries | np.timedelta64) -> TimestampSeries: ... # type: ignore[override] | ||
def __add__(self, other: TimedeltaSeries | np.timedelta64 | timedelta) -> TimestampSeries: ... # type: ignore[override] | ||
def __radd__(self, other: TimedeltaSeries | np.timedelta64 | timedelta) -> TimestampSeries: ... # type: ignore[override] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently pyright 1.1.310 had bugs that revealed we were missing some types here |
||
@overload # type: ignore[override] | ||
def __sub__( | ||
self, other: Timestamp | datetime | TimestampSeries | ||
) -> TimedeltaSeries: ... | ||
@overload | ||
def __sub__( | ||
self, | ||
other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64, | ||
other: timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64, | ||
) -> TimestampSeries: ... | ||
def __mul__(self, other: float | Series[int] | Series[float] | Sequence[float]) -> TimestampSeries: ... # type: ignore[override] | ||
def __truediv__(self, other: float | Series[int] | Series[float] | Sequence[float]) -> TimestampSeries: ... # type: ignore[override] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
from pandas.core.window import ExponentialMovingWindow | ||
import pytest | ||
from typing_extensions import ( | ||
Self, | ||
TypeAlias, | ||
assert_type, | ||
) | ||
|
@@ -1604,12 +1605,14 @@ def test_pandera_generic() -> None: | |
T = TypeVar("T") | ||
|
||
class MySeries(pd.Series, Generic[T]): | ||
... | ||
def __new__(cls, *args, **kwargs) -> Self: | ||
return object.__new__(cls) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes |
||
|
||
def func() -> MySeries[float]: | ||
return MySeries[float]([1, 2, 3]) | ||
|
||
func() | ||
result = func() | ||
assert result.iloc[1] == 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I modified the test to make sure that defining |
||
|
||
|
||
def test_change_to_dict_return_type() -> None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See point #3 at microsoft/pyright#5178 (comment) , Recommended to use a
Union
rather than a constrained type var.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also affect other TypeVars (could be done later)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
S1 = TypeVar("S1", bound=Scalar)
? You replacedS1
withScalar
in some placesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work (but Scalar includes a few more types!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and I created an issue for that #719