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 all commits
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
2 changes: 1 addition & 1 deletion pandas-stubs/_libs/sparse.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class SparseIndex(object): ...
class SparseIndex: ...
class BlockIndex(SparseIndex): ...
class IntIndex(SparseIndex): ...
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 @@ -1113,7 +1113,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
4 changes: 2 additions & 2 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ class Index(IndexOpsMixin, PandasObject):
@property
def shape(self) -> Tuple[int, ...]: ...
# Extra methods from old stubs
def __eq__(self, other: object) -> np_ndarray_bool: ... # type: ignore
def __eq__(self, other: object) -> np_ndarray_bool: ... # type: ignore[override]
def __iter__(self) -> Iterator: ...
def __ne__(self, other: object) -> np_ndarray_bool: ... # type: ignore
def __ne__(self, other: object) -> np_ndarray_bool: ... # 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 @@ -1113,7 +1113,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 @@ -1144,7 +1144,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
1 change: 0 additions & 1 deletion pandas-stubs/core/sparse/api.pyi
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

6 changes: 1 addition & 5 deletions pandas-stubs/io/pickle.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import sys
from typing import (
Literal,
Optional,
Union,
)

from pandas._typing import FilePathOrBuffer as FilePathOrBuffer

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal

def to_pickle(
obj,
filepath_or_buffer: FilePathOrBuffer,
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,12 @@ warn_unreachable = false # GH#27396
# Suppressing errors
show_none_errors = true
ignore_errors = false
enable_error_code = "ignore-without-code" # same as in pandas
# Miscellaneous strictness flags
allow_untyped_globals = false
allow_redefinition = false
local_partial_types = false
implicit_reexport = true
implicit_reexport = false # pyright behaves the same
strict_equality = true
# Configuring error messages
show_error_context = false
Expand Down
2 changes: 1 addition & 1 deletion tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,4 +1084,4 @@ def test_set_columns() -> None:
df = pd.DataFrame({"a": [1, 2, 3], "b": [0.0, 1, 1]})
# Next line should work, but it is a mypy bug
# https://github.com/python/mypy/issues/3004
df.columns = ["c", "d"] # type: ignore
df.columns = ["c", "d"] # type: ignore[assignment]
16 changes: 8 additions & 8 deletions tests/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,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 # type: ignore[operator]
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 +66,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 # type: ignore[operator]
i2 + pd.Timedelta(seconds=20) # type: ignore[operator]

i3 = pd.Interval(13.2, 19.5)
assert_type(i3.length, "float")
Expand All @@ -80,5 +80,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 # type: ignore[operator]
i3 + pd.Timedelta(seconds=20) # type: ignore[operator]
4 changes: 2 additions & 2 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ 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 # type: ignore[operator]
ts = pd.Timestamp("2022-06-30")
tsum: pd.Series = s1 + ts # type: ignore
tsum: pd.Series = s1 + ts # type: ignore[operator]


def test_dtindex_tzinfo() -> None:
Expand Down