From 552715a877ba13cb303db145402dd6ab3546d209 Mon Sep 17 00:00:00 2001 From: Marco Gorelli Date: Thu, 28 Jan 2021 16:59:01 +0000 Subject: [PATCH] annotate some variables, remove some unused --- pandas/_config/display.py | 3 ++- pandas/core/computation/expressions.py | 10 ++++++---- pandas/core/generic.py | 5 ++--- pandas/core/series.py | 2 +- pandas/io/excel/_base.py | 1 - pandas/io/excel/_util.py | 4 ++-- pandas/io/sql.py | 2 +- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pandas/_config/display.py b/pandas/_config/display.py index e4553a2107f87..ec819481525da 100644 --- a/pandas/_config/display.py +++ b/pandas/_config/display.py @@ -4,12 +4,13 @@ import locale import sys +from typing import Optional from pandas._config import config as cf # ----------------------------------------------------------------------------- # Global formatting options -_initial_defencoding = None +_initial_defencoding: Optional[str] = None def detect_console_encoding() -> str: diff --git a/pandas/core/computation/expressions.py b/pandas/core/computation/expressions.py index e5ede3cd885be..087b7f39e3374 100644 --- a/pandas/core/computation/expressions.py +++ b/pandas/core/computation/expressions.py @@ -6,13 +6,15 @@ """ import operator -from typing import List, Set +from typing import List, Optional, Set import warnings import numpy as np from pandas._config import get_option +from pandas._typing import FuncType + from pandas.core.dtypes.generic import ABCDataFrame from pandas.core.computation.check import NUMEXPR_INSTALLED @@ -21,11 +23,11 @@ if NUMEXPR_INSTALLED: import numexpr as ne -_TEST_MODE = None +_TEST_MODE: Optional[bool] = None _TEST_RESULT: List[bool] = [] USE_NUMEXPR = NUMEXPR_INSTALLED -_evaluate = None -_where = None +_evaluate: Optional[FuncType] = None +_where: Optional[FuncType] = None # the set of dtypes that we will allow pass to numexpr _ALLOWED_DTYPES = { diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 96b35f1aaab9c..5d668b9668e5a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -180,7 +180,7 @@ class NDFrame(PandasObject, SelectionMixin, indexing.IndexingMixin): ["_AXIS_NAMES", "_AXIS_NUMBERS", "get_values", "tshift"] ) _metadata: List[str] = [] - _is_copy = None + _is_copy: Optional[weakref.ReferenceType[NDFrame]] = None _mgr: Manager _attrs: Dict[Optional[Hashable], Any] _typ: str @@ -405,7 +405,6 @@ def _data(self): # Axis _stat_axis_number = 0 _stat_axis_name = "index" - _ix = None _AXIS_ORDERS: List[str] _AXIS_TO_AXIS_NUMBER: Dict[Axis, int] = {0: 0, "index": 0, "rows": 0} _AXIS_REVERSED: bool @@ -3831,7 +3830,7 @@ def _slice(self: FrameOrSeries, slobj: slice, axis=0) -> FrameOrSeries: return result @final - def _set_is_copy(self, ref, copy: bool_t = True) -> None: + def _set_is_copy(self, ref: FrameOrSeries, copy: bool_t = True) -> None: if not copy: self._is_copy = None else: diff --git a/pandas/core/series.py b/pandas/core/series.py index f75292f32dbca..81db9a29c514d 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -412,7 +412,7 @@ def _constructor_expanddim(self) -> Type[DataFrame]: def _can_hold_na(self) -> bool: return self._mgr._can_hold_na - _index = None + _index: Optional[Index] = None def _set_axis(self, axis: int, labels, fastpath: bool = False) -> None: """ diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 11974d25d72d3..085df983c3669 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -747,7 +747,6 @@ def __new__(cls, path, engine=None, **kwargs): return object.__new__(cls) # declare external properties you can count on - curr_sheet = None path = None @property diff --git a/pandas/io/excel/_util.py b/pandas/io/excel/_util.py index ab8e0fca4bf38..01ccc9d15a6a3 100644 --- a/pandas/io/excel/_util.py +++ b/pandas/io/excel/_util.py @@ -1,10 +1,10 @@ -from typing import List +from typing import List, MutableMapping from pandas.compat._optional import import_optional_dependency from pandas.core.dtypes.common import is_integer, is_list_like -_writers = {} +_writers: MutableMapping[str, str] = {} def register_writer(klass): diff --git a/pandas/io/sql.py b/pandas/io/sql.py index e1af3169420fc..725cb633918e7 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -35,7 +35,7 @@ class DatabaseError(IOError): # ----------------------------------------------------------------------------- # -- Helper functions -_SQLALCHEMY_INSTALLED = None +_SQLALCHEMY_INSTALLED: Optional[bool] = None def _is_sqlalchemy_connectable(con):