@@ -598,11 +598,9 @@ def get_loc(self, key, method=None, tolerance=None):
598
598
TypeError
599
599
If key is listlike or otherwise not hashable.
600
600
"""
601
-
602
601
if isinstance (key , str ):
603
602
try :
604
- asdt , parsed , reso = parse_time_string (key , self .freq )
605
- key = asdt
603
+ key , parsed , reso = parse_time_string (key , self .freq )
606
604
except DateParseError :
607
605
# A string with invalid format
608
606
raise KeyError (f"Cannot interpret '{ key } ' as period" )
@@ -613,25 +611,21 @@ def get_loc(self, key, method=None, tolerance=None):
613
611
614
612
try :
615
613
key = Period (key , freq = self .freq )
614
+ ordinal = key .ordinal if key is not NaT else key .value
616
615
except ValueError :
617
616
# we cannot construct the Period
618
617
# as we have an invalid type
619
618
if is_list_like (key ):
620
619
raise TypeError (f"'{ key } ' is an invalid key" )
621
620
raise KeyError (key )
622
621
623
- ordinal = key .ordinal if key is not NaT else key .value
622
+ if tolerance is not None :
623
+ tolerance = self ._convert_tolerance (tolerance , np .asarray (key ))
624
+
624
625
try :
625
- return self ._engine .get_loc (ordinal )
626
+ return self ._int64index .get_loc (ordinal , method , tolerance )
626
627
except KeyError :
627
-
628
- try :
629
- if tolerance is not None :
630
- tolerance = self ._convert_tolerance (tolerance , np .asarray (key ))
631
- return self ._int64index .get_loc (ordinal , method , tolerance )
632
-
633
- except KeyError :
634
- raise KeyError (key )
628
+ raise KeyError (key )
635
629
636
630
def _maybe_cast_slice_bound (self , label , side , kind ):
637
631
"""
0 commit comments