From 51a4b625144980d946f49bd93e38c1c37076e3d0 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Mon, 2 Dec 2019 00:27:20 +0200 Subject: [PATCH] Typing --- pandas/_libs/tslibs/offsets.pyx | 3 ++- pandas/core/arrays/sparse/dtype.py | 2 +- pandas/core/dtypes/base.py | 4 ++-- pandas/core/dtypes/dtypes.py | 6 +++--- pandas/core/indexes/frozen.py | 4 +++- pandas/io/pytables.py | 4 ++-- pandas/io/stata.py | 3 ++- pandas/tseries/offsets.py | 4 ++-- 8 files changed, 17 insertions(+), 13 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index c8985c365741d..41420dbceef9d 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1,6 +1,7 @@ import cython import time +from typing import Any from cpython.datetime cimport (PyDateTime_IMPORT, PyDateTime_Check, PyDelta_Check, @@ -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 diff --git a/pandas/core/arrays/sparse/dtype.py b/pandas/core/arrays/sparse/dtype.py index 0124304727ab3..4fb64ec9255e1 100644 --- a/pandas/core/arrays/sparse/dtype.py +++ b/pandas/core/arrays/sparse/dtype.py @@ -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): diff --git a/pandas/core/dtypes/base.py b/pandas/core/dtypes/base.py index 8acdf32c8768e..063014cbe970d 100644 --- a/pandas/core/dtypes/base.py +++ b/pandas/core/dtypes/base.py @@ -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 @@ -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. diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index 9414786424245..f2e2b31f903f5 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -765,7 +765,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 @@ -904,7 +904,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() @@ -1077,7 +1077,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): diff --git a/pandas/core/indexes/frozen.py b/pandas/core/indexes/frozen.py index 2ea83ba889fd2..27f88933f9998 100644 --- a/pandas/core/indexes/frozen.py +++ b/pandas/core/indexes/frozen.py @@ -7,6 +7,8 @@ """ +from typing import Any + from pandas.core.base import PandasObject from pandas.io.formats.printing import pprint_thing @@ -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) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 29835a9bd0c00..81f10d917ea38 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -1770,7 +1770,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) @@ -2098,7 +2098,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) diff --git a/pandas/io/stata.py b/pandas/io/stata.py index b592b560bb5a0..eaecc0627e693 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -15,6 +15,7 @@ import os import struct import sys +from typing import Any import warnings from dateutil.relativedelta import relativedelta @@ -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 diff --git a/pandas/tseries/offsets.py b/pandas/tseries/offsets.py index 96a9ad1e4d5f2..75698f7354bf9 100644 --- a/pandas/tseries/offsets.py +++ b/pandas/tseries/offsets.py @@ -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 @@ -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