MCPcopy Index your code
hub / github.com/pydata/xarray / _get_date_field

Function _get_date_field

xarray/core/accessor_dt.py:107–149  ·  view source on GitHub ↗

Indirectly access pandas' libts.get_date_field by wrapping data as a Series and calling through `.dt` attribute. Parameters ---------- values : np.ndarray or dask.array-like Array-like container of datetime-like values name : str Name of datetime field to access

(values, name, dtype)

Source from the content-addressed store, hash-verified

105
106
107def _get_date_field(values, name, dtype):
108 """Indirectly access pandas' libts.get_date_field by wrapping data
109 as a Series and calling through `.dt` attribute.
110
111 Parameters
112 ----------
113 values : np.ndarray or dask.array-like
114 Array-like container of datetime-like values
115 name : str
116 Name of datetime field to access
117 dtype : dtype-like
118 dtype for output date field values
119
120 Returns
121 -------
122 datetime_fields : same type as values
123 Array-like of datetime fields accessed for each element in values
124
125 """
126 if is_np_datetime_like(values.dtype):
127 access_method = _access_through_series
128 else:
129 access_method = _access_through_cftimeindex
130
131 if is_duck_dask_array(values):
132 from dask.array import map_blocks
133
134 new_axis = chunks = None
135 # isocalendar adds an axis
136 if name == "isocalendar":
137 chunks = (3,) + values.chunksize
138 new_axis = 0
139
140 return map_blocks(
141 access_method, values, name, dtype=dtype, new_axis=new_axis, chunks=chunks
142 )
143 else:
144 out = access_method(values, name)
145 # cast only for integer types to keep float64 in presence of NaT
146 # see https://github.com/pydata/xarray/issues/7928
147 if np.issubdtype(out.dtype, np.integer):
148 out = out.astype(dtype, copy=False)
149 return out
150
151
152def _round_through_series_or_index(values, name, freq):

Callers 2

_date_fieldMethod · 0.85
isocalendarMethod · 0.85

Calls 4

is_np_datetime_likeFunction · 0.90
is_duck_dask_arrayFunction · 0.90
map_blocksFunction · 0.90
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…