Skip to content

CLN: Prune unnecessary indexing code #27576

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 12 commits into from
Jul 25, 2019
Prev Previous commit
Next Next commit
Merge branch 'master' of https://github.com/pandas-dev/pandas into mi…
…ndex
  • Loading branch information
jbrockmendel committed Jul 25, 2019
commit 743e7c09fb25e96ebbeccab310d7e8aac52b4806
77 changes: 22 additions & 55 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3231,41 +3231,8 @@ def _create_indexer(cls, name, indexer):
_indexer = functools.partial(indexer, name)
setattr(cls, name, property(_indexer, doc=indexer.__doc__))

def get(self, key, default=None):
"""
Get item from object for given key (ex: DataFrame column).

Returns default value if not found.

Parameters
----------
key : object

Returns
-------
value : same type as items contained in object
"""
try:
return self[key]
except (KeyError, ValueError, IndexError):
return default

def __getitem__(self, item):
raise AbstractMethodError(self)

def _get_item_cache(self, item):
"""Return the cached item, item represents a label indexer."""
cache = self._item_cache
res = cache.get(item)
if res is None:
values = self._data.get(item)
res = self._box_item_values(item, values)
cache[item] = res
res._set_as_cached(item, self)

# for a chain
res._is_copy = self._is_copy
return res
# ----------------------------------------------------------------------
# Lookup Caching

def _set_as_cached(self, item, cacher):
"""Set the _cacher attribute on the calling object with a weakref to
Expand Down Expand Up @@ -3589,27 +3556,8 @@ class animal locomotion

_xs = xs # type: Callable

def get(self, key, default=None):
"""
Get item from object for given key (ex: DataFrame column).

Returns default value if not found.

Parameters
----------
key : object

Returns
-------
value : same type as items contained in object
"""
try:
return self[key]
except (KeyError, ValueError, IndexError):
return default

def __getitem__(self, item):
return self._get_item_cache(item)
raise AbstractMethodError(self)

def _get_item_cache(self, item):
"""Return the cached item, item represents a label indexer."""
Expand Down Expand Up @@ -3800,6 +3748,25 @@ def __delitem__(self, key):
# ----------------------------------------------------------------------
# Unsorted

def get(self, key, default=None):
"""
Get item from object for given key (ex: DataFrame column).

Returns default value if not found.

Parameters
----------
key : object

Returns
-------
value : same type as items contained in object
"""
try:
return self[key]
except (KeyError, ValueError, IndexError):
return default

@property
def _is_view(self):
"""Return boolean indicating if self is view of another array """
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.