From b63f829466fd6999c7c28a6ae81038bed8ae0d94 Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Wed, 16 Oct 2019 19:53:41 +0100 Subject: [PATCH] CLN: Clean DirNameMixin (#28957) --- pandas/core/accessor.py | 6 ++---- pandas/core/arrays/categorical.py | 4 +++- pandas/core/base.py | 14 ++++++++++++-- pandas/core/indexes/base.py | 12 ++++++------ pandas/core/series.py | 4 +--- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/pandas/core/accessor.py b/pandas/core/accessor.py index bce6c352ce480..fc60c01d7b808 100644 --- a/pandas/core/accessor.py +++ b/pandas/core/accessor.py @@ -4,7 +4,7 @@ that can be mixed into or pinned onto other pandas classes. """ -from typing import Set +from typing import FrozenSet, Set import warnings from pandas.util._decorators import Appender @@ -12,9 +12,7 @@ class DirNamesMixin: _accessors = set() # type: Set[str] - _deprecations = frozenset( - ["asobject", "base", "data", "flags", "itemsize", "strides"] - ) + _deprecations = frozenset() # type: FrozenSet[str] def _dir_deletions(self): """ diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index ea19808b19fc9..d34cf3e576beb 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -331,7 +331,9 @@ class Categorical(ExtensionArray, PandasObject): __array_priority__ = 1000 _dtype = CategoricalDtype(ordered=False) # tolist is not actually deprecated, just suppressed in the __dir__ - _deprecations = PandasObject._deprecations | frozenset(["tolist", "get_values"]) + _deprecations = PandasObject._deprecations | frozenset( + ["tolist", "itemsize", "get_values"] + ) _typ = "categorical" def __init__( diff --git a/pandas/core/base.py b/pandas/core/base.py index c461a1509ec78..5ae3926952a67 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -4,7 +4,7 @@ import builtins from collections import OrderedDict import textwrap -from typing import Dict, Optional +from typing import Dict, FrozenSet, Optional import warnings import numpy as np @@ -651,7 +651,17 @@ class IndexOpsMixin: # ndarray compatibility __array_priority__ = 1000 - _deprecations = frozenset(["item"]) + _deprecations = frozenset( + [ + "tolist", # tolist is not deprecated, just suppressed in the __dir__ + "base", + "data", + "item", + "itemsize", + "flags", + "strides", + ] + ) # type: FrozenSet[str] def transpose(self, *args, **kwargs): """ diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 464cd49f135ae..526b2c2e2c412 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1,7 +1,7 @@ from datetime import datetime import operator from textwrap import dedent -from typing import Union +from typing import FrozenSet, Union import warnings import numpy as np @@ -63,7 +63,7 @@ from pandas.core.dtypes.missing import array_equivalent, isna from pandas.core import ops -from pandas.core.accessor import CachedAccessor, DirNamesMixin +from pandas.core.accessor import CachedAccessor import pandas.core.algorithms as algos from pandas.core.arrays import ExtensionArray from pandas.core.base import IndexOpsMixin, PandasObject @@ -206,10 +206,10 @@ class Index(IndexOpsMixin, PandasObject): # tolist is not actually deprecated, just suppressed in the __dir__ _deprecations = ( - IndexOpsMixin._deprecations - | DirNamesMixin._deprecations - | frozenset(["tolist", "contains", "dtype_str", "get_values", "set_value"]) - ) + PandasObject._deprecations + | IndexOpsMixin._deprecations + | frozenset(["asobject", "contains", "dtype_str", "get_values", "set_value"]) + ) # type: FrozenSet[str] # To hand over control to subclasses _join_precedence = 1 diff --git a/pandas/core/series.py b/pandas/core/series.py index 539a09f7046ac..1039e9af929d4 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -54,7 +54,7 @@ import pandas as pd from pandas.core import algorithms, base, generic, nanops, ops -from pandas.core.accessor import CachedAccessor, DirNamesMixin +from pandas.core.accessor import CachedAccessor from pandas.core.arrays import ExtensionArray from pandas.core.arrays.categorical import Categorical, CategoricalAccessor from pandas.core.arrays.sparse import SparseAccessor @@ -178,10 +178,8 @@ class Series(base.IndexOpsMixin, generic.NDFrame): _deprecations = ( base.IndexOpsMixin._deprecations | generic.NDFrame._deprecations - | DirNamesMixin._deprecations | frozenset( [ - "tolist", # tolist is not deprecated, just suppressed in the __dir__ "asobject", "compress", "valid",