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

Method indexer_at_time

pandas/core/indexes/datetimes.py:1105–1182  ·  view source on GitHub ↗

Return index locations of values at particular time of day. Parameters ---------- time : datetime.time or str Time passed in either as object (datetime.time) or as string in appropriate format ("%H:%M", "%H%M", "%I:%M%p", "%I%M%p",

(self, time, asof: bool = False)

Source from the content-addressed store, hash-verified

1103 return "datetime64"
1104
1105 def indexer_at_time(self, time, asof: bool = False) -> npt.NDArray[np.intp]:
1106 """
1107 Return index locations of values at particular time of day.
1108
1109 Parameters
1110 ----------
1111 time : datetime.time or str
1112 Time passed in either as object (datetime.time) or as string in
1113 appropriate format ("%H:%M", "%H%M", "%I:%M%p", "%I%M%p",
1114 "%H:%M:%S", "%H%M%S", "%I:%M:%S%p", "%I%M%S%p").
1115 asof : bool, default False
1116 This parameter is currently not supported.
1117
1118 Returns
1119 -------
1120 np.ndarray[np.intp]
1121 Index locations of values at given `time` of day.
1122
1123 See Also
1124 --------
1125 indexer_between_time : Get index locations of values between particular
1126 times of day.
1127 DataFrame.at_time : Select values at particular time of day.
1128
1129 Examples
1130 --------
1131 >>> idx = pd.DatetimeIndex(
1132 ... ["1/1/2020 10:00", "2/1/2020 11:00", "3/1/2020 10:00"]
1133 ... )
1134 >>> idx.indexer_at_time("10:00")
1135 array([0, 2])
1136 """
1137 if asof:
1138 raise NotImplementedError("'asof' argument is not supported")
1139
1140 if isinstance(time, str):
1141 from dateutil.parser import parse
1142
1143 orig = time
1144 try:
1145 alt = to_time(time)
1146 except ValueError:
1147 warnings.warn(
1148 # GH#50839
1149 f"The string '{orig}' cannot be parsed using pd.core.tools.to_time "
1150 f"and in a future version will raise. "
1151 "Use an unambiguous time string format or explicitly cast to "
1152 "`datetime.time` before calling.",
1153 Pandas4Warning,
1154 stacklevel=find_stack_level(),
1155 )
1156 time = parse(time).time()
1157 else:
1158 try:
1159 time = parse(time).time()
1160 except ValueError:
1161 # e.g. '23550' raises dateutil.parser._parser.ParserError
1162 time = alt

Callers 2

get_locMethod · 0.95
at_timeMethod · 0.80

Calls 8

_get_time_microsMethod · 0.95
tz_convertMethod · 0.95
to_timeFunction · 0.90
find_stack_levelFunction · 0.90
parseFunction · 0.85
_time_to_microsFunction · 0.85
timeMethod · 0.80
nonzeroMethod · 0.80

Tested by

no test coverage detected