Skip to content

REF: avoid calling engine for EA values #31258

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
Jan 23, 2020
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
9 changes: 6 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2892,14 +2892,17 @@ def _get_value(self, index, col, takeable: bool = False):
engine = self.index._engine

try:
return engine.get_value(series._values, index)
if isinstance(series._values, np.ndarray):
Copy link
Contributor

Choose a reason for hiding this comment

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

i understand why you are doing this (does it affect perf btw?)

but is not a great long term pattern. can you instead factor this to a function (which you can also use in Series)?

Copy link
Member Author

Choose a reason for hiding this comment

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

long-term this is going to be made unnecessary when Series._values is changed to match Index._values. At that point libindex.get_value_at and IndexEngine.get_value will become entirely unnecessary

Copy link
Contributor

Choose a reason for hiding this comment

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

k sounds like a plan!

# i.e. not EA, we can use engine
return engine.get_value(series._values, index)
else:
loc = series.index.get_loc(index)
return series._values[loc]
except KeyError:
# GH 20629
if self.index.nlevels > 1:
# partial indexing forbidden
raise
except (TypeError, ValueError):
pass

# we cannot handle direct indexing
# use positional
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2101,8 +2101,7 @@ def __setitem__(self, key, value):
if len(key) != self.ndim:
raise ValueError("Not enough indexers for scalar access (setting)!")
key = list(self._convert_key(key, is_setter=True))
key.append(value)
self.obj._set_value(*key, takeable=self._takeable)
self.obj._set_value(*key, value=value, takeable=self._takeable)


@Appender(IndexingMixin.at.__doc__)
Expand Down
7 changes: 5 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,9 +1060,12 @@ def _set_value(self, label, value, takeable: bool = False):
try:
if takeable:
self._values[label] = value
else:
elif isinstance(self._values, np.ndarray):
# i.e. not EA, so we can use _engine
self.index._engine.set_value(self._values, label, value)
except (KeyError, TypeError):
else:
self.loc[label] = value
except KeyError:

# set using a non-recursive method
self.loc[label] = value
Expand Down