|
3 | 3 | import enum
|
4 | 4 | import functools
|
5 | 5 | import operator
|
| 6 | +import warnings |
6 | 7 | from collections import Counter, defaultdict
|
7 | 8 | from collections.abc import Hashable, Iterable, Mapping
|
8 | 9 | from contextlib import suppress
|
@@ -588,6 +589,14 @@ def __getitem__(self, key: Any):
|
588 | 589 | return result
|
589 | 590 |
|
590 | 591 |
|
| 592 | +BackendArray_fallback_warning_message = ( |
| 593 | + "The array `{0}` does not support indexing using the .vindex and .oindex properties. " |
| 594 | + "The __getitem__ method is being used instead. This fallback behavior will be " |
| 595 | + "removed in a future version. Please ensure that the backend array `{1}` implements " |
| 596 | + "support for the .vindex and .oindex properties to avoid potential issues." |
| 597 | +) |
| 598 | + |
| 599 | + |
591 | 600 | class LazilyIndexedArray(ExplicitlyIndexedNDArrayMixin):
|
592 | 601 | """Wrap an array to make basic and outer indexing lazy."""
|
593 | 602 |
|
@@ -639,11 +648,18 @@ def shape(self) -> _Shape:
|
639 | 648 | return tuple(shape)
|
640 | 649 |
|
641 | 650 | def get_duck_array(self):
|
642 |
| - if isinstance(self.array, ExplicitlyIndexedNDArrayMixin): |
| 651 | + try: |
643 | 652 | array = apply_indexer(self.array, self.key)
|
644 |
| - else: |
| 653 | + except NotImplementedError as _: |
645 | 654 | # If the array is not an ExplicitlyIndexedNDArrayMixin,
|
646 |
| - # it may wrap a BackendArray so use its __getitem__ |
| 655 | + # it may wrap a BackendArray subclass that doesn't implement .oindex and .vindex. so use its __getitem__ |
| 656 | + warnings.warn( |
| 657 | + BackendArray_fallback_warning_message.format( |
| 658 | + self.array.__class__.__name__, self.array.__class__.__name__ |
| 659 | + ), |
| 660 | + category=DeprecationWarning, |
| 661 | + stacklevel=2, |
| 662 | + ) |
647 | 663 | array = self.array[self.key]
|
648 | 664 |
|
649 | 665 | # self.array[self.key] is now a numpy array when
|
@@ -715,12 +731,20 @@ def shape(self) -> _Shape:
|
715 | 731 | return np.broadcast(*self.key.tuple).shape
|
716 | 732 |
|
717 | 733 | def get_duck_array(self):
|
718 |
| - if isinstance(self.array, ExplicitlyIndexedNDArrayMixin): |
| 734 | + try: |
719 | 735 | array = apply_indexer(self.array, self.key)
|
720 |
| - else: |
| 736 | + except NotImplementedError as _: |
721 | 737 | # If the array is not an ExplicitlyIndexedNDArrayMixin,
|
722 |
| - # it may wrap a BackendArray so use its __getitem__ |
| 738 | + # it may wrap a BackendArray subclass that doesn't implement .oindex and .vindex. so use its __getitem__ |
| 739 | + warnings.warn( |
| 740 | + BackendArray_fallback_warning_message.format( |
| 741 | + self.array.__class__.__name__, self.array.__class__.__name__ |
| 742 | + ), |
| 743 | + category=PendingDeprecationWarning, |
| 744 | + stacklevel=2, |
| 745 | + ) |
723 | 746 | array = self.array[self.key]
|
| 747 | + |
724 | 748 | # self.array[self.key] is now a numpy array when
|
725 | 749 | # self.array is a BackendArray subclass
|
726 | 750 | # and self.key is BasicIndexer((slice(None, None, None),))
|
|
0 commit comments