Skip to content

Commit

Permalink
Workaround for Pandas issue 42430
Browse files Browse the repository at this point in the history
  • Loading branch information
frreiss committed Jul 7, 2021
1 parent d804c92 commit 5b1b9fb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions text_extensions_for_pandas/array/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,24 @@ def __getitem__(self, item) -> Union["TensorArray", "TensorElement"]:
See docstring in `Extension Array` class in `pandas/core/arrays/base.py`
for information about this method.
"""
# Return scalar if single value is selected, a TensorElement for single array element,
# or TensorArray for slice
# Return scalar if single value is selected, a TensorElement for single array
# element, or TensorArray for slice
if isinstance(item, int):
value = self._tensor[item]
if np.isscalar(value):
return value
else:
return TensorElement(value)
else:
# BEGIN workaround for Pandas issue #42430
if (pd.__version__ == "1.3.0" and isinstance(item, tuple) and len(item) > 1
and item[0] == Ellipsis):
if len(item) > 2:
# Hopefully this case is not possible, but can't be sure
raise ValueError(f"Workaround Pandas issue #42430 not implemented "
f"for tuple length > 2")
item = item[1]
# END workaround for issue #42430
if isinstance(item, TensorArray):
item = np.asarray(item)
item = check_array_indexer(self, item)
Expand Down

0 comments on commit 5b1b9fb

Please sign in to comment.