Skip to content

Commit 3c5e4c6

Browse files
allow list-length-1-with-slice corner case
1 parent 097d221 commit 3c5e4c6

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

pandas/core/arrays/datetimelike.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,18 @@ def __getitem__(self, key):
518518
return type(self)(val, dtype=self.dtype)
519519

520520
if com.is_bool_indexer(key):
521-
# first check for boolean, because check_array_indexer doesn't
521+
# first convert to boolean, because check_array_indexer doesn't
522522
# allow object dtype
523523
key = np.asarray(key, dtype=bool)
524524
key = check_array_indexer(self, key)
525525
if key.all():
526526
key = slice(0, None, None)
527527
else:
528528
key = lib.maybe_booleans_to_slice(key.view(np.uint8))
529+
elif isinstance(key, list) and len(key) == 1 and isinstance(key[0], slice):
530+
# see https://github.com/pandas-dev/pandas/issues/31299, need to allow
531+
# this for now (would otherwise raise in check_array_indexer)
532+
pass
529533
elif is_list_like(key) and not isinstance(key, tuple):
530534
key = check_array_indexer(self, key)
531535

pandas/core/arrays/interval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def __len__(self) -> int:
496496
return len(self.left)
497497

498498
def __getitem__(self, value):
499-
if is_list_like(value):
499+
if is_list_like(value) and not isinstance(value, tuple):
500500
value = check_array_indexer(self, value)
501501
left = self.left[value]
502502
right = self.right[value]

pandas/core/arrays/masked.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __getitem__(self, item):
3939
return self.dtype.na_value
4040
return self._data[item]
4141

42-
elif is_list_like(item):
42+
elif is_list_like(item) and not isinstance(item, tuple):
4343
item = check_array_indexer(self, item)
4444

4545
return type(self)(self._data[item], self._mask[item])

pandas/core/arrays/numpy_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def __getitem__(self, item):
234234
if isinstance(item, type(self)):
235235
item = item._ndarray
236236

237-
elif is_list_like(item):
237+
elif is_list_like(item) and not isinstance(item, tuple):
238238
item = check_array_indexer(self, item)
239239

240240
result = self._ndarray[item]

pandas/core/arrays/sparse/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ def __getitem__(self, key):
770770
else:
771771
key = np.asarray(key)
772772

773-
if is_list_like(key):
773+
if is_list_like(key) and not isinstance(key, tuple):
774774
key = check_array_indexer(self, key)
775775

776776
if com.is_bool_indexer(key):

0 commit comments

Comments
 (0)