MCPcopy
hub / github.com/pydata/xarray / _generate_linear_date_range

Function _generate_linear_date_range

xarray/coding/cftime_offsets.py:865–879  ·  view source on GitHub ↗

Generate an equally-spaced sequence of cftime.datetime objects between and including two dates (whose length equals the number of periods).

(start, end, periods)

Source from the content-addressed store, hash-verified

863
864
865def _generate_linear_date_range(start, end, periods):
866 """Generate an equally-spaced sequence of cftime.datetime objects between
867 and including two dates (whose length equals the number of periods)."""
868 if TYPE_CHECKING:
869 import cftime
870 else:
871 cftime = attempt_import("cftime")
872
873 total_seconds = (end - start).total_seconds()
874 values = np.linspace(0.0, total_seconds, periods, endpoint=True)
875 units = f"seconds since {format_cftime_datetime(start)}"
876 calendar = start.calendar
877 return cftime.num2date(
878 values, units=units, calendar=calendar, only_use_cftime_datetimes=True
879 )
880
881
882def _generate_linear_date_range_with_freq(start, end, periods, freq):

Callers 1

_cftime_rangeFunction · 0.85

Calls 4

attempt_importFunction · 0.90
format_cftime_datetimeFunction · 0.90
total_secondsMethod · 0.80
linspaceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…