Skip to content

CLN: Clean DirNameMixin._deprecated #28957

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

Merged
merged 1 commit into from
Oct 16, 2019
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
6 changes: 2 additions & 4 deletions pandas/core/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
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


class DirNamesMixin:
_accessors = set() # type: Set[str]
_deprecations = frozenset(
["asobject", "base", "data", "flags", "itemsize", "strides"]
)
_deprecations = frozenset() # type: FrozenSet[str]

def _dir_deletions(self):
"""
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down
14 changes: 12 additions & 2 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -653,7 +653,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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might not need this annotation; I think mypy should be able to infer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried again, and mypy complains without the annotation. My guess is that it cannot be sure that the added set should only contain strings.


def transpose(self, *args, **kwargs):
"""
Expand Down
12 changes: 6 additions & 6 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the type hints after complaints from mypy. I agree it's strange it doesn't infer and I'll see if something can be done to make it infer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think should be able to infer as long as you construct with values. Empty construction complains because it is not known then what types of value the object should hold.

Not sure if FrozenSet would act differently but that’s how builtins work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. A frozenset that only contains strings, could conceivably have non-strings, and I think that's what mypy complains about.


# To hand over control to subclasses
_join_precedence = 1
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down