MCPcopy
hub / github.com/pandas-dev/pandas / get_loc

Method get_loc

pandas/core/indexes/datetimes.py:948–998  ·  view source on GitHub ↗

Get integer location for requested label Returns ------- loc : int

(self, key)

Source from the content-addressed store, hash-verified

946 raise KeyError(key) from err
947
948 def get_loc(self, key):
949 """
950 Get integer location for requested label
951
952 Returns
953 -------
954 loc : int
955 """
956 self._check_indexing_error(key)
957
958 orig_key = key
959 if is_valid_na_for_dtype(key, self.dtype):
960 key = NaT
961
962 if isinstance(key, self._data._recognized_scalars):
963 # needed to localize naive datetimes
964 self._disallow_mismatched_indexing(key)
965 key = Timestamp(key)
966
967 elif isinstance(key, str):
968 try:
969 parsed, reso = self._parse_with_reso(key)
970 except ValueError as err:
971 raise KeyError(key) from err
972 self._disallow_mismatched_indexing(parsed)
973
974 if self._can_partial_date_slice(reso):
975 try:
976 return self._partial_date_slice(reso, parsed)
977 except KeyError as err:
978 raise KeyError(key) from err
979
980 key = parsed
981
982 elif isinstance(key, dt.timedelta):
983 # GH#20464
984 raise TypeError(
985 f"Cannot index {type(self).__name__} with {type(key).__name__}"
986 )
987
988 elif isinstance(key, dt.time):
989 return self.indexer_at_time(key)
990
991 else:
992 # unrecognized type
993 raise KeyError(key)
994
995 try:
996 return Index.get_loc(self, key)
997 except KeyError as err:
998 raise KeyError(orig_key) from err
999
1000 def _maybe_cast_slice_bound(self, label, side: str):
1001 """

Calls 7

_parse_with_resoMethod · 0.95
indexer_at_timeMethod · 0.95
is_valid_na_for_dtypeFunction · 0.90
_partial_date_sliceMethod · 0.80
_check_indexing_errorMethod · 0.45