MCPcopy Create free account
hub / github.com/pydata/xarray / month_anchor_check

Function month_anchor_check

xarray/coding/frequencies.py:248–276  ·  view source on GitHub ↗

Return the monthly offset string. Return "cs" if all dates are the first days of the month, "ce" if all dates are the last day of the month, None otherwise. Replicated pandas._libs.tslibs.resolution.month_position_check but without business offset handling.

(dates)

Source from the content-addressed store, hash-verified

246
247
248def month_anchor_check(dates):
249 """Return the monthly offset string.
250
251 Return "cs" if all dates are the first days of the month,
252 "ce" if all dates are the last day of the month,
253 None otherwise.
254
255 Replicated pandas._libs.tslibs.resolution.month_position_check
256 but without business offset handling.
257 """
258 calendar_end = True
259 calendar_start = True
260
261 for date in dates:
262 if calendar_start:
263 calendar_start &= date.day == 1
264
265 if calendar_end:
266 cal = date.day == date.daysinmonth
267 calendar_end &= cal
268 elif not calendar_start:
269 break
270
271 if calendar_end:
272 return "ce"
273 elif calendar_start:
274 return "cs"
275 else:
276 return None

Callers 3

_get_annual_ruleMethod · 0.85
_get_quartely_ruleMethod · 0.85
_get_monthly_ruleMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…