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

Function _access_through_series

xarray/core/accessor_dt.py:74–104  ·  view source on GitHub ↗

Coerce an array of datetime-like values to a pandas Series and access requested datetime component

(values, name)

Source from the content-addressed store, hash-verified

72
73
74def _access_through_series(values, name):
75 """Coerce an array of datetime-like values to a pandas Series and
76 access requested datetime component
77 """
78 values_as_series = pd.Series(duck_array_ops.ravel(values), copy=False)
79 if name == "season":
80 months = values_as_series.dt.month.values
81 field_values = _season_from_months(months)
82 elif name == "total_seconds":
83 field_values = values_as_series.dt.total_seconds().values
84 elif name == "isocalendar":
85 # special NaT-handling can be removed when
86 # https://github.com/pandas-dev/pandas/issues/54657 is resolved
87 field_values = values_as_series.dt.isocalendar()
88 # test for <NA> and apply needed dtype
89 hasna = any(field_values.year.isnull())
90 if hasna:
91 field_values = np.dstack(
92 [
93 getattr(field_values, name).astype(np.float64, copy=False).values
94 for name in ["year", "week", "day"]
95 ]
96 )
97 else:
98 field_values = np.array(field_values, dtype=np.int64)
99 # isocalendar returns iso- year, week, and weekday -> reshape
100 return field_values.T.reshape(3, *values.shape)
101 else:
102 field_values = getattr(values_as_series.dt, name).values
103
104 return field_values.reshape(values.shape)
105
106
107def _get_date_field(values, name, dtype):

Callers

nothing calls this directly

Calls 5

_season_from_monthsFunction · 0.85
total_secondsMethod · 0.80
isocalendarMethod · 0.80
isnullMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…