Skip to content

WIP: Refactor accessors, unify usage, make "recipe" #17042

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

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b77e103
Move PandasDelegate and AccessorProperty; update imports
jbrockmendel Jul 19, 2017
dbc149d
Move apply _shared_docs to functions and attach to methods with copy
jbrockmendel Jul 20, 2017
3c77d94
Implement _make_accessor as classmethod on StringMethods
jbrockmendel Jul 20, 2017
19f7ff6
Add example/recipe
jbrockmendel Jul 20, 2017
d152421
Test to go along with example/recipe
jbrockmendel Jul 20, 2017
101e7e5
Transition to _make_accessor
jbrockmendel Jul 20, 2017
774a35d
Merge branch 'master' into accessory
jbrockmendel Jul 20, 2017
ccec595
Merge branch 'master' into accessory
jbrockmendel Jul 20, 2017
74e4539
Remove unused import that was causing a lint error
jbrockmendel Jul 20, 2017
953598a
merge pulled
jbrockmendel Jul 20, 2017
22d4892
Wrap long line
jbrockmendel Jul 22, 2017
014fae0
Refactor tests and documentation
jbrockmendel Jul 22, 2017
dd8315c
Typos, flake8 fixes, rearrange comments
jbrockmendel Jul 22, 2017
74a237b
Simplify categorical make_accessor args
jbrockmendel Jul 23, 2017
c931d4b
Rename PandasDelegate subclasses FooDelegate
jbrockmendel Jul 25, 2017
6c771b4
Revert import rearrangement; update names FooDelegate
jbrockmendel Jul 25, 2017
d3a4460
Deprecate StringAccessorMixin
jbrockmendel Jul 25, 2017
48f3b4d
Merge branch 'master' into accessory
jbrockmendel Jul 25, 2017
73a0633
lint fixes
jbrockmendel Jul 25, 2017
aa793ad
Merge branch 'accessory' of https://github.com/jbrockmendel/pandas in…
jbrockmendel Jul 25, 2017
264a7e7
Merge branch 'master' into accessory
jbrockmendel Sep 20, 2017
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
Prev Previous commit
Next Next commit
Simplify categorical make_accessor args
  • Loading branch information
jbrockmendel committed Jul 23, 2017
commit 74a237b8fceedb2ca79d4524a7da8624071c2417
8 changes: 4 additions & 4 deletions pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2055,11 +2055,11 @@ def _make_accessor(cls, values):
if not is_categorical_dtype(values.dtype):
msg = "Can only use .cat accessor with a 'category' dtype"
raise AttributeError(msg)
return CategoricalAccessor(values.values, values.index)
return CategoricalAccessor(values)

def __init__(self, values, index):
self.categorical = values
self.index = index
def __init__(self, values):
self.categorical = values.values
self.index = values.index
self._freeze()

def _delegate_property_get(self, name):
Expand Down
6 changes: 1 addition & 5 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ def _create_from_codes(self, codes, categories=None, ordered=None,
-------
CategoricalIndex
"""

from pandas.core.categorical import Categorical
if categories is None:
categories = self.categories
if ordered is None:
Expand Down Expand Up @@ -154,7 +152,6 @@ def _create_categorical(self, data, categories=None, ordered=None):
"""
if not isinstance(data, ABCCategorical):
ordered = False if ordered is None else ordered
from pandas.core.categorical import Categorical
data = Categorical(data, categories=categories, ordered=ordered)
else:
if categories is not None:
Expand Down Expand Up @@ -403,7 +400,6 @@ def where(self, cond, other=None):
other = self._na_value
values = np.where(cond, self.values, other)

from pandas.core.categorical import Categorical
cat = Categorical(values,
categories=self.categories,
ordered=self.ordered)
Expand Down Expand Up @@ -698,6 +694,7 @@ def _evaluate_compare(self, other):
cls.__le__ = _make_compare('__le__')
cls.__ge__ = _make_compare('__ge__')

# TODO: Can we de-duplicate this with core.categorical Delegate?
def _delegate_method(self, name, *args, **kwargs):
""" method delegation to the ._values """
method = getattr(self._values, name)
Expand All @@ -708,7 +705,6 @@ def _delegate_method(self, name, *args, **kwargs):
return res
return CategoricalIndex(res, name=self.name)


CategoricalIndex._add_numeric_methods_add_sub_disabled()
CategoricalIndex._add_numeric_methods_disabled()
CategoricalIndex._add_logical_methods_disabled()
Expand Down