|
69 | 69 | from pandas.core.arrays import ExtensionArray
|
70 | 70 | from pandas.core.base import IndexOpsMixin, PandasObject
|
71 | 71 | import pandas.core.common as com
|
| 72 | +from pandas.core.construction import extract_array |
72 | 73 | from pandas.core.indexers import maybe_convert_indices
|
73 | 74 | from pandas.core.indexes.frozen import FrozenList
|
74 | 75 | import pandas.core.missing as missing
|
@@ -4489,22 +4490,26 @@ def get_value(self, series, key):
|
4489 | 4490 | # if we have something that is Index-like, then
|
4490 | 4491 | # use this, e.g. DatetimeIndex
|
4491 | 4492 | # Things like `Series._get_value` (via .at) pass the EA directly here.
|
4492 |
| - s = getattr(series, "_values", series) |
4493 |
| - if isinstance(s, (ExtensionArray, Index)) and is_scalar(key): |
4494 |
| - # GH 20882, 21257 |
4495 |
| - # Unify Index and ExtensionArray treatment |
4496 |
| - # First try to convert the key to a location |
4497 |
| - # If that fails, raise a KeyError if an integer |
4498 |
| - # index, otherwise, see if key is an integer, and |
4499 |
| - # try that |
4500 |
| - try: |
4501 |
| - iloc = self.get_loc(key) |
4502 |
| - return s[iloc] |
4503 |
| - except KeyError: |
4504 |
| - if len(self) > 0 and (self.holds_integer() or self.is_boolean()): |
4505 |
| - raise |
4506 |
| - elif is_integer(key): |
4507 |
| - return s[key] |
| 4493 | + s = extract_array(series, extract_numpy=True) |
| 4494 | + if isinstance(s, ExtensionArray): |
| 4495 | + if is_scalar(key): |
| 4496 | + # GH 20882, 21257 |
| 4497 | + # First try to convert the key to a location |
| 4498 | + # If that fails, raise a KeyError if an integer |
| 4499 | + # index, otherwise, see if key is an integer, and |
| 4500 | + # try that |
| 4501 | + try: |
| 4502 | + iloc = self.get_loc(key) |
| 4503 | + return s[iloc] |
| 4504 | + except KeyError: |
| 4505 | + if len(self) > 0 and (self.holds_integer() or self.is_boolean()): |
| 4506 | + raise |
| 4507 | + elif is_integer(key): |
| 4508 | + return s[key] |
| 4509 | + else: |
| 4510 | + # if key is not a scalar, directly raise an error (the code below |
| 4511 | + # would convert to numpy arrays and raise later any way) - GH29926 |
| 4512 | + raise InvalidIndexError(key) |
4508 | 4513 |
|
4509 | 4514 | s = com.values_from_object(series)
|
4510 | 4515 | k = com.values_from_object(key)
|
|
0 commit comments