@@ -538,21 +538,6 @@ def __getitem__(self, key):
538
538
This getitem defers to the underlying array, which by-definition can
539
539
only handle list-likes, slices, and integer scalars
540
540
"""
541
- is_int = lib .is_integer (key )
542
- if lib .is_scalar (key ) and not is_int :
543
- raise IndexError (
544
- "only integers, slices (`:`), ellipsis (`...`), "
545
- "numpy.newaxis (`None`) and integer or boolean "
546
- "arrays are valid indices"
547
- )
548
-
549
- getitem = self ._data .__getitem__
550
- if is_int :
551
- val = getitem (key )
552
- if lib .is_scalar (val ):
553
- # i.e. self.ndim == 1
554
- return self ._box_func (val )
555
- return type (self )(val , dtype = self .dtype )
556
541
557
542
if com .is_bool_indexer (key ):
558
543
# first convert to boolean, because check_array_indexer doesn't
@@ -569,6 +554,16 @@ def __getitem__(self, key):
569
554
else :
570
555
key = check_array_indexer (self , key )
571
556
557
+ freq = self ._get_getitem_freq (key )
558
+ result = self ._data [key ]
559
+ if lib .is_scalar (result ):
560
+ return self ._box_func (result )
561
+ return self ._simple_new (result , dtype = self .dtype , freq = freq )
562
+
563
+ def _get_getitem_freq (self , key ):
564
+ """
565
+ Find the `freq` attribute to assign to the result of a __getitem__ lookup.
566
+ """
572
567
is_period = is_period_dtype (self .dtype )
573
568
if is_period :
574
569
freq = self .freq
@@ -583,11 +578,7 @@ def __getitem__(self, key):
583
578
# GH#21282 indexing with Ellipsis is similar to a full slice,
584
579
# should preserve `freq` attribute
585
580
freq = self .freq
586
-
587
- result = getitem (key )
588
- if lib .is_scalar (result ):
589
- return self ._box_func (result )
590
- return self ._simple_new (result , dtype = self .dtype , freq = freq )
581
+ return freq
591
582
592
583
def __setitem__ (
593
584
self ,
0 commit comments