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

Method _generate_range

pandas/core/arrays/timedeltas.py:292–332  ·  view source on GitHub ↗
(
        cls, start, end, periods, freq, closed=None, *, unit: TimeUnit
    )

Source from the content-addressed store, hash-verified

290
291 @classmethod
292 def _generate_range(
293 cls, start, end, periods, freq, closed=None, *, unit: TimeUnit
294 ) -> Self:
295 periods = dtl.validate_periods(periods)
296 if freq is None and any(x is None for x in [periods, start, end]):
297 raise ValueError("Must provide freq argument if no data is supplied")
298
299 if com.count_not_none(start, end, periods, freq) != 3:
300 raise ValueError(
301 "Of the four parameters: start, end, periods, "
302 "and freq, exactly three must be specified"
303 )
304
305 if start is not None:
306 start = Timedelta(start).as_unit("ns")
307
308 if end is not None:
309 end = Timedelta(end).as_unit("ns")
310
311 if unit not in ["s", "ms", "us", "ns"]:
312 raise ValueError("'unit' must be one of 's', 'ms', 'us', 'ns'")
313
314 if start is not None and unit is not None:
315 start = start.as_unit(unit, round_ok=False)
316 if end is not None and unit is not None:
317 end = end.as_unit(unit, round_ok=False)
318
319 left_closed, right_closed = validate_endpoints(closed)
320
321 if freq is not None:
322 index = generate_regular_range(start, end, periods, freq, unit=unit)
323 else:
324 index = np.linspace(start._value, end._value, periods).astype("i8")
325
326 if not left_closed:
327 index = index[1:]
328 if not right_closed:
329 index = index[:-1]
330
331 td64values = index.view(f"m8[{unit}]")
332 return cls._simple_new(td64values, dtype=td64values.dtype, freq=freq)
333
334 # ----------------------------------------------------------------
335 # DatetimeLike Interface

Callers

nothing calls this directly

Calls 6

validate_endpointsFunction · 0.90
generate_regular_rangeFunction · 0.90
as_unitMethod · 0.45
astypeMethod · 0.45
viewMethod · 0.45
_simple_newMethod · 0.45

Tested by

no test coverage detected