Skip to content
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

CI: enable a few more mypy checks #60

Merged
merged 8 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas-stubs/core/arraylike.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ from pandas._typing import (
class OpsMixinProtocol(Protocol): ...

class OpsMixin:
def __eq__(self: OpsMixinProtocol, other: Any) -> DataFrame: ... # type: ignore
def __ne__(self: OpsMixinProtocol, other: Any) -> DataFrame: ... # type: ignore
def __eq__(self: OpsMixinProtocol, other: Any) -> DataFrame: ... # type: ignore[override]
def __ne__(self: OpsMixinProtocol, other: Any) -> DataFrame: ... # type: ignore[override]
def __lt__(self: OpsMixinProtocol, other: Any) -> DataFrame: ...
def __le__(self: OpsMixinProtocol, other: Any) -> DataFrame: ...
def __gt__(self: OpsMixinProtocol, other: Any) -> DataFrame: ...
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ class DataFrame(NDFrame, OpsMixin):
@property
def columns(self) -> Index: ...
@columns.setter # setter needs to be right next to getter; otherwise mypy complains
def columns(self, cols: Union[List[_str], Index[_str]]) -> None: ... # type:ignore
def columns(self, cols: Union[List[_str], Index[_str]]) -> None: ... # type: ignore[type-arg]
@property
def dtypes(self) -> Series: ...
@property
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Index(IndexOpsMixin, PandasObject):
# Extra methods from old stubs
def __eq__(self, other: object) -> bool: ... # Series: ... # type: ignore
def __iter__(self) -> Iterator: ...
def __ne__(self, other: _str) -> Index: ... # type: ignore
def __ne__(self, other: _str) -> Index: ... # type: ignore[override]
def to_numpy(self) -> np.ndarray: ...

def ensure_index_from_sequences(
Expand Down
4 changes: 2 additions & 2 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
def __and__(self, other: Union[_ListLike, Series[S1]]) -> Series[_bool]: ...
# def __array__(self, dtype: Optional[_bool] = ...) -> _np_ndarray
def __div__(self, other: Union[num, _ListLike, Series[S1]]) -> Series[S1]: ...
def __eq__(self, other: object) -> Series[_bool]: ... # type: ignore
def __eq__(self, other: object) -> Series[_bool]: ... # type: ignore[override]
def __floordiv__(self, other: Union[num, _ListLike, Series[S1]]) -> Series[int]: ...
def __ge__(
self, other: Union[num, _ListLike, Series[S1], Timestamp]
Expand Down Expand Up @@ -1135,7 +1135,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
@overload
def __mul__(self, other: Union[num, _ListLike, Series]) -> Series: ...
def __mod__(self, other: Union[num, _ListLike, Series[S1]]) -> Series[S1]: ...
def __ne__(self, other: object) -> Series[_bool]: ... # type: ignore
def __ne__(self, other: object) -> Series[_bool]: ... # type: ignore[override]
def __pow__(self, other: Union[num, _ListLike, Series[S1]]) -> Series[S1]: ...
def __or__(self, other: Union[_ListLike, Series[S1]]) -> Series[_bool]: ...
def __radd__(
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,19 @@ no_implicit_optional = true
strict_optional = true
# Configuring warnings
warn_redundant_casts = true
warn_unused_ignores = false # Change from pandas
warn_unused_ignores = true
warn_no_return = true
warn_return_any = false # TODO
warn_unreachable = false # GH#27396
# Suppressing errors
show_none_errors = true
ignore_errors = false
enable_error_code = "ignore-without-code"
# Miscellaneous strictness flags
allow_untyped_globals = false
allow_redefinition = false
local_partial_types = false
implicit_reexport = true
implicit_reexport = false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add comment here and with enable_error_code that these are changes from pandas?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implicit_reexport is still true in pandas

strict_equality = true
# Configuring error messages
show_error_context = false
Expand Down
17 changes: 9 additions & 8 deletions tests/test_interval.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# flake8: noqa: F841
# pyright: reportUnusedExpression = false
from typing import TYPE_CHECKING

import pandas as pd
Expand Down Expand Up @@ -47,10 +48,10 @@ def test_interval_length() -> None:

assert_type(idres, "pd.Interval[pd.Timestamp]")
if TYPE_CHECKING:
20 in i1 # type: ignore
i1 + pd.Timestamp("2000-03-03") # type: ignore
i1 * 3 # type: ignore
i1 * pd.Timedelta(seconds=20) # type: ignore
20 in i1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this type: ignore means we think this code is legal, but it shouldn't be. You can't check that an int is contained inside of an Interval[Timestamp], so the type checker should pick that up.

I'm hesitant to make this change unless we can fix the stub to error out on this line.

I'm pretty sure at one point it did used to pick that up - not sure what changed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will take quite some effort to remove annotations like these

def __add__(self, other: TimestampSeries) -> TimestampSeries: ...
def __add__(self, other: Timestamp) -> TimestampSeries: ..

but also allow legit combinations.

i1 + pd.Timestamp("2000-03-03") # type: ignore[operator]
i1 * 3 # type: ignore[operator]
i1 * pd.Timedelta(seconds=20) # type: ignore[operator]

i2 = pd.Interval(10, 20)
assert_type(i2.length, "int")
Expand All @@ -66,8 +67,8 @@ def test_interval_length() -> None:
assert_type(i2 * 4.2, "pd.Interval[float]")

if TYPE_CHECKING:
pd.Timestamp("2001-01-02") in i2 # type: ignore
i2 + pd.Timedelta(seconds=20) # type: ignore
pd.Timestamp("2001-01-02") in i2 # pyright: ignore[reportGeneralTypeIssues]
i2 + pd.Timedelta(seconds=20) # pyright: ignore[reportGeneralTypeIssues]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of these cases where pyright is correctly picking up the error, but mypy is not.


i3 = pd.Interval(13.2, 19.5)
assert_type(i3.length, "float")
Expand All @@ -80,5 +81,5 @@ def test_interval_length() -> None:
assert_type(i3 + 3, "pd.Interval[float]")
assert_type(i3 * 3, "pd.Interval[float]")
if TYPE_CHECKING:
pd.Timestamp("2001-01-02") in i3 # type: ignore
i3 + pd.Timedelta(seconds=20) # type: ignore
pd.Timestamp("2001-01-02") in i3 # pyright: ignore[reportGeneralTypeIssues]
i3 + pd.Timedelta(seconds=20) # pyright: ignore[reportGeneralTypeIssues]
4 changes: 2 additions & 2 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,6 @@ def fail_on_adding_two_timestamps() -> None:
s1 = pd.Series(pd.to_datetime(["2022-05-01", "2022-06-01"]))
s2 = pd.Series(pd.to_datetime(["2022-05-15", "2022-06-15"]))
if TYPE_CHECKING:
ssum: pd.Series = s1 + s2 # type: ignore
ssum: pd.Series = s1 + s2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this should have a # type: ignore, because we should be picking up that this is not allowed, i.e., you can't add two series consisting of Timestamps.

ts = pd.Timestamp("2022-06-30")
tsum: pd.Series = s1 + ts # type: ignore
tsum: pd.Series = s1 + ts