Skip to content

Commit

Permalink
Typing (pandas-dev#29947)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaharNaveh authored and proost committed Dec 19, 2019
1 parent 0372e23 commit ae783f2
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 13 deletions.
3 changes: 2 additions & 1 deletion pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import cython

import time
from typing import Any
from cpython.datetime cimport (PyDateTime_IMPORT,
PyDateTime_Check,
PyDelta_Check,
Expand Down Expand Up @@ -328,7 +329,7 @@ class _BaseOffset:
def __setattr__(self, name, value):
raise AttributeError("DateOffset objects are immutable.")

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
if isinstance(other, str):
try:
# GH#23524 if to_offset fails, we are dealing with an
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __hash__(self):
# __eq__, so we explicitly do it here.
return super().__hash__()

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
# We have to override __eq__ to handle NA values in _metadata.
# The base class does simple == checks, which fail for NA.
if isinstance(other, str):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Extend pandas with custom array types"""
from typing import List, Optional, Tuple, Type
from typing import Any, List, Optional, Tuple, Type

import numpy as np

Expand Down Expand Up @@ -86,7 +86,7 @@ def __from_arrow__(
def __str__(self) -> str:
return self.name

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
"""
Check whether 'other' is equal to self.
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def __hash__(self) -> int:
# TODO: update this.
return hash(str(self))

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
if isinstance(other, str):
return other == self.name

Expand Down Expand Up @@ -903,7 +903,7 @@ def __hash__(self) -> int:
# make myself hashable
return hash(str(self))

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
if isinstance(other, str):
return other == self.name or other == self.name.title()

Expand Down Expand Up @@ -1076,7 +1076,7 @@ def __hash__(self) -> int:
# make myself hashable
return hash(str(self))

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
if isinstance(other, str):
return other.lower() in (self.name.lower(), str(self).lower())
elif not isinstance(other, IntervalDtype):
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"""

from typing import Any

from pandas.core.base import PandasObject

from pandas.io.formats.printing import pprint_thing
Expand Down Expand Up @@ -71,7 +73,7 @@ def __radd__(self, other):
other = list(other)
return type(self)(other + list(self))

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
if isinstance(other, (tuple, FrozenList)):
other = list(other)
return super().__eq__(other)
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ def __repr__(self) -> str:
)
)

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
""" compare 2 col items """
return all(
getattr(self, a, None) == getattr(other, a, None)
Expand Down Expand Up @@ -2113,7 +2113,7 @@ def __repr__(self) -> str:
)
)

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
""" compare 2 col items """
return all(
getattr(self, a, None) == getattr(other, a, None)
Expand Down
3 changes: 2 additions & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import struct
import sys
from typing import Any
import warnings

from dateutil.relativedelta import relativedelta
Expand Down Expand Up @@ -857,7 +858,7 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return f"{type(self)}({self})"

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
return (
isinstance(other, type(self))
and self.string == other.string
Expand Down
4 changes: 2 additions & 2 deletions pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import date, datetime, timedelta
import functools
import operator
from typing import Optional
from typing import Any, Optional

from dateutil.easter import easter
import numpy as np
Expand Down Expand Up @@ -2551,7 +2551,7 @@ def __add__(self, other):
f"the add operation between {self} and {other} will overflow"
)

def __eq__(self, other) -> bool:
def __eq__(self, other: Any) -> bool:
if isinstance(other, str):
from pandas.tseries.frequencies import to_offset

Expand Down

0 comments on commit ae783f2

Please sign in to comment.